Skip to content

Commit e1fdca2

Browse files
nobutmm1
authored andcommitted
proc.c: fix inherited method owner
* proc.c (mnew_from_me): keep iclass as-is, to make inheritance chain consistent. [ruby-core:59358] [Bug ruby#9315] * proc.c (method_owner): return the original defined_class from prepended iclass, instead. * vm_insnhelper.c (vm_search_super_method): revert r44455, no longer defined_class becomes a module. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e test for prev
1 parent 08775a2 commit e1fdca2

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

proc.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,10 +1171,6 @@ mnew_from_me(rb_method_entry_t *me, VALUE defined_class, VALUE klass,
11711171
goto again;
11721172
}
11731173

1174-
if (RB_TYPE_P(defined_class, T_ICLASS)) {
1175-
defined_class = RBASIC_CLASS(defined_class);
1176-
}
1177-
11781174
klass = defined_class;
11791175

11801176
while (rclass != klass &&
@@ -1396,9 +1392,16 @@ static VALUE
13961392
method_owner(VALUE obj)
13971393
{
13981394
struct METHOD *data;
1395+
VALUE defined_class;
13991396

14001397
TypedData_Get_Struct(obj, struct METHOD, &method_data_type, data);
1401-
return data->defined_class;
1398+
defined_class = data->defined_class;
1399+
1400+
if (RB_TYPE_P(defined_class, T_ICLASS)) {
1401+
defined_class = RBASIC_CLASS(defined_class);
1402+
}
1403+
1404+
return defined_class;
14021405
}
14031406

14041407
void

test/ruby/test_super.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,19 @@ def test_super_splat
407407
assert_equal([false, false], y.foo(false, false))
408408
assert_equal([1, 2, 3, false, 5], y.foo(1, 2, 3, false, 5))
409409
end
410+
411+
def test_missing_super_in_method_module
412+
bug9315 = '[ruby-core:59358] [Bug #9315]'
413+
a = Module.new do
414+
def foo
415+
super
416+
end
417+
end
418+
b = Class.new do
419+
include a
420+
end
421+
assert_raise(NoMethodError, bug9315) do
422+
b.new.method(:foo).call
423+
end
424+
end
410425
end

0 commit comments

Comments
 (0)