[PRISM] Use the splatkw instruction

Fixes ruby/prism#2272.
This commit is contained in:
Peter Zhu 2024-01-29 09:47:52 -05:00
parent e050097beb
commit 9a5a11f3d0
2 changed files with 31 additions and 5 deletions

View File

@ -2749,13 +2749,17 @@ pm_compile_call(rb_iseq_t *iseq, const pm_call_node_t *call_node, LINK_ANCHOR *c
else if (!popped) {
ADD_INSN1(ret, &dummy_line_node, setn, INT2FIX(orig_argc + 1));
}
}
if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
ADD_INSN(ret, &dummy_line_node, splatkw);
}
ADD_SEND_R(ret, &dummy_line_node, method_id, INT2FIX(orig_argc), block_iseq, INT2FIX(flags), kw_arg);
if (pm_node->flags & PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) {
PM_POP_UNLESS_POPPED;
}
else {
ADD_SEND_R(ret, &dummy_line_node, method_id, INT2FIX(orig_argc), block_iseq, INT2FIX(flags), kw_arg);
}
if (call_node->base.flags & PM_CALL_NODE_FLAGS_SAFE_NAVIGATION) {
ADD_INSNL(ret, &dummy_line_node, jump, end_label);

View File

@ -827,6 +827,28 @@ module Prism
o.bar(hello: "world")
RUBY
# Test that AssocSplatNode is evaluated before BlockArgumentNode using
# the splatkw instruction
assert_prism_eval(<<~RUBY)
o = Struct.new(:ary) do
def to_hash
ary << :to_hash
{}
end
def to_proc
ary << :to_proc
-> {}
end
def t(...); end
end.new
o.ary = []
o.t(**o, &o)
o.ary
RUBY
end
def test_HashNode