Skip to content

Commit d8a13e5

Browse files
Peter Zhupeterzhu2118
authored andcommitted
[Bug #17780] Fix Method#super_method for module alias
Method#super_method crashes for aliased module methods because they are not defined on a class. This bug was introduced in c60aaed as part of bug #17130.
1 parent 587e680 commit d8a13e5

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,7 +3227,7 @@ method_super_method(VALUE method)
32273227
TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
32283228
iclass = data->iclass;
32293229
if (!iclass) return Qnil;
3230-
if (data->me->def->type == VM_METHOD_TYPE_ALIAS) {
3230+
if (data->me->def->type == VM_METHOD_TYPE_ALIAS && data->me->defined_class) {
32313231
super_class = RCLASS_SUPER(rb_find_defined_class_by_owner(data->me->defined_class,
32323232
data->me->def->body.alias.original_me->owner));
32333233
mid = data->me->def->body.alias.original_me->def->original_id;

test/ruby/test_method.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,19 @@ def m1
11681168
assert_nil(m.super_method)
11691169
end
11701170

1171+
# Bug 17780
1172+
def test_super_method_module_alias
1173+
m = Module.new do
1174+
def foo
1175+
end
1176+
alias :f :foo
1177+
end
1178+
1179+
method = m.instance_method(:f)
1180+
super_method = method.super_method
1181+
assert_nil(super_method)
1182+
end
1183+
11711184
def rest_parameter(*rest)
11721185
rest
11731186
end

0 commit comments

Comments
 (0)