From 24c3331bdfa47339de70e5866132bf872e6d9d90 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 28 Dec 2013 23:21:14 +0000 Subject: [PATCH] vm_insnhelper.c: missing super in method module * vm_insnhelper.c (vm_search_super_method): direct superclass of a module is found when super called in a Method object generated a method defined in a module, call method_missing in that case. [ruby-core:59358] [Bug #9315] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ test/ruby/test_super.rb | 15 +++++++++++++++ vm_insnhelper.c | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/ChangeLog b/ChangeLog index f293481f87..7457abdef8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Dec 29 08:21:09 2013 Nobuyoshi Nakada + + * vm_insnhelper.c (vm_search_super_method): direct superclass of a + module is found when super called in a Method object generated a + method defined in a module, call method_missing in that case. + [ruby-core:59358] [Bug #9315] + Sun Dec 29 07:27:51 2013 Benoit Daloze * compar.c (cmp_eq_recursive): Fix the return value, the value for diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb index 846f40946d..b518aa2914 100644 --- a/test/ruby/test_super.rb +++ b/test/ruby/test_super.rb @@ -407,4 +407,19 @@ class TestSuper < Test::Unit::TestCase assert_equal([false, false], y.foo(false, false)) assert_equal([1, 2, 3, false, 5], y.foo(1, 2, 3, false, 5)) end + + def test_missing_super_in_method_module + bug9315 = '[ruby-core:59358] [Bug #9315]' + a = Module.new do + def foo + super + end + end + b = Class.new do + include a + end + assert_raise(NoMethodError, bug9315) do + b.new.method(:foo).call + end + end end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index c8cbaa07bf..8694f524f6 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2024,6 +2024,11 @@ vm_search_super_method(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_inf " by define_method() is not supported." " Specify all arguments explicitly."); } + if (!ci->klass) { + ci->aux.missing_reason = NOEX_SUPER; + CI_SET_FASTPATH(ci, vm_call_method_missing, 1); + return; + } /* TODO: use inline cache */ ci->me = rb_method_entry(ci->klass, ci->mid, &ci->defined_class);