Ensure super(**kw, &block) calls kw.to_hash before block.to_proc

Similar as previous commit, but handles the super case with
explicit arguments.
This commit is contained in:
Jeremy Evans 2023-12-07 12:16:09 -08:00
parent a950f23078
commit f64357540e
2 changed files with 23 additions and 0 deletions

View File

@ -9229,6 +9229,9 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i
VALUE vargc = setup_args(iseq, args, RNODE_SUPER(node)->nd_args, &flag, &keywords);
CHECK(!NIL_P(vargc));
argc = FIX2INT(vargc);
if ((flag & VM_CALL_ARGS_BLOCKARG) && (flag & VM_CALL_KW_SPLAT) && !(flag & VM_CALL_KW_SPLAT_MUT)) {
ADD_INSN(args, node, splatkw);
}
}
else {
/* NODE_ZSUPER */

View File

@ -164,6 +164,26 @@ class TestCall < Test::Unit::TestCase
assert_equal([:to_a, :to_hash, :to_proc], ary)
end
def test_kwsplat_block_order_super
def self.t(splat)
o = Object.new
ary = []
o.define_singleton_method(:to_a) {ary << :to_a; []}
o.define_singleton_method(:to_hash) {ary << :to_hash; {}}
o.define_singleton_method(:to_proc) {ary << :to_proc; lambda{}}
if splat
super(*o, **o, &o)
else
super(**o, &o)
end
ary
end
extend Module.new{def t(...) end}
assert_equal([:to_hash, :to_proc], t(false))
assert_equal([:to_a, :to_hash, :to_proc], t(true))
end
OVER_STACK_LEN = (ENV['RUBY_OVER_STACK_LEN'] || 150).to_i # Greater than VM_ARGC_STACK_MAX
OVER_STACK_ARGV = OVER_STACK_LEN.times.to_a.freeze