Skip to content

Commit 6013958

Browse files
nobutmm1
authored andcommitted
vm_insnhelper.c: revive r44455 for bound module method
* vm_insnhelper.c (vm_search_super_method): when super called in a bound UnboundMethod generated from a module, no superclass is found since the current defined class is the module, then call method_missing in that case. [ruby-core:59619] [Bug ruby#9377] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e Conflicts: ChangeLog
1 parent 86946e7 commit 6013958

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

test/ruby/test_super.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,17 @@ def foo
440440
assert_equal(:ok, o.method(:foo).call, bug9315)
441441
end
442442
end
443+
444+
def test_missing_super_in_module_unbound_method
445+
bug9377 = '[ruby-core:59619] [Bug #9377]'
446+
447+
a = Module.new do
448+
def foo; super end
449+
end
450+
451+
m = a.instance_method(:foo).bind(Object.new.extend(a))
452+
assert_raise(NoMethodError, bug9377) do
453+
m.call
454+
end
455+
end
443456
end

vm_insnhelper.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,12 @@ vm_search_super_method(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_inf
20242024
" by define_method() is not supported."
20252025
" Specify all arguments explicitly.");
20262026
}
2027+
if (!ci->klass) {
2028+
/* bound instance method of module */
2029+
ci->aux.missing_reason = NOEX_SUPER;
2030+
CI_SET_FASTPATH(ci, vm_call_method_missing, 1);
2031+
return;
2032+
}
20272033

20282034
/* TODO: use inline cache */
20292035
ci->me = rb_method_entry(ci->klass, ci->mid, &ci->defined_class);

0 commit comments

Comments
 (0)