summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Gruber <[email protected]>2024-09-07 12:17:08 -0400
committerKevin Newton <[email protected]>2024-09-11 16:41:46 -0400
commit5d358b660d41e64de301f428dc0300a52a6f9566 ()
tree69e684e87941e0001e1446664b2a7e53af49fd25
parentd4d6f1de83628b12e4a27d273edace7762f69860 (diff)
Fix issue with super and forwarding arguments in prism_compile.c
Fixes [Bug #20720]
Notes: Merged: https://.com/ruby/ruby/pull/11565
-rw-r--r--parse.y4
-rw-r--r--prism_compile.c10
-rw-r--r--test/ruby/test_super.rb16
3 files changed, 24 insertions, 6 deletions
@@ -15132,11 +15132,11 @@ new_args_forward_call(struct parser_params *p, NODE *leading, const YYLTYPE *loc
#ifndef FORWARD_ARGS_WITH_RUBY2_KEYWORDS
NODE *kwrest = list_append(p, NEW_LIST(0, loc), NEW_LVAR(idFWD_KWREST, loc));
#endif
- rb_node_block_pass_t *block = NEW_BLOCK_PASS(NEW_LVAR(idFWD_BLOCK, loc), loc);
NODE *args = leading ? rest_arg_append(p, leading, rest, argsloc) : NEW_SPLAT(rest, loc);
block->forwarding = TRUE;
#ifndef FORWARD_ARGS_WITH_RUBY2_KEYWORDS
- args = arg_append(p, args, new_hash(p, kwrest, loc), loc);
#endif
return arg_blk_pass(args, block);
}
@@ -1708,7 +1708,7 @@ pm_setup_args_core(const pm_arguments_node_t *arguments_node, const pm_node_t *b
break;
}
- case PM_FORWARDING_ARGUMENTS_NODE: {
if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
*flags |= VM_CALL_FORWARDING;
@@ -9628,9 +9628,10 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
}
return;
}
- case PM_SUPER_NODE: {
// super(foo)
- // ^^^^^^^^^^
const pm_super_node_t *cast = (const pm_super_node_t *) node;
DECL_ANCHOR(args);
@@ -9649,6 +9650,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
int flags = 0;
struct rb_callinfo_kwarg *keywords = NULL;
int argc = pm_setup_args(cast->arguments, cast->block, &flags, &keywords, iseq, ret, scope_node, &location);
flags |= VM_CALL_SUPER | VM_CALL_FCALL;
if (cast->block && PM_NODE_TYPE_P(cast->block, PM_BLOCK_NODE)) {
@@ -9668,7 +9670,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
}
PUSH_SEQ(ret, args);
- if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
flags |= VM_CALL_FORWARDING;
PUSH_INSN2(ret, location, invokesuperforward, new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL), current_block);
}
@@ -8,6 +8,7 @@ class TestSuper < Test::Unit::TestCase
def array(*a) a end
def optional(a = 0) a end
def keyword(**a) a end
end
class Single1 < Base
def single(*) super end
@@ -63,6 +64,16 @@ class TestSuper < Test::Unit::TestCase
[x, y]
end
end
def test_single1
assert_equal(1, Single1.new.single(1))
@@ -133,6 +144,11 @@ class TestSuper < Test::Unit::TestCase
def test_keyword2
assert_equal([{foo: "changed1"}, {foo: "changed2"}], Keyword2.new.keyword)
end
class A
def tt(aa)