diff options
author | Peter Zhu <peter.zhu@shopify.com> | 2021-04-07 18:25:16 +0000 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2021-04-07 15:16:58 -0400 |
commit | d8a13e504992a45d52063f7c925408d7aad3595a (patch) | |
tree | 2a5691c5fde93b6df53446b139accadec3ea7104 | |
parent | 587e6800086764a1b7c959976acef33e230dccc2 (diff) | |
download | ruby-d8a13e504992a45d52063f7c925408d7aad3595a.tar.gz |
[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
c60aaed1856b2b6f90de0992c34771830019e021 as part of bug #17130.
-rw-r--r-- | proc.c | 2 | ||||
-rw-r--r-- | test/ruby/test_method.rb | 13 |
2 files changed, 14 insertions, 1 deletions
@@ -3227,7 +3227,7 @@ method_super_method(VALUE method) TypedData_Get_Struct(method, struct METHOD, &method_data_type, data); iclass = data->iclass; if (!iclass) return Qnil; - if (data->me->def->type == VM_METHOD_TYPE_ALIAS) { + if (data->me->def->type == VM_METHOD_TYPE_ALIAS && data->me->defined_class) { super_class = RCLASS_SUPER(rb_find_defined_class_by_owner(data->me->defined_class, data->me->def->body.alias.original_me->owner)); mid = data->me->def->body.alias.original_me->def->original_id; diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index cc7421b700..240821c9e2 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -1168,6 +1168,19 @@ class TestMethod < Test::Unit::TestCase assert_nil(m.super_method) end + # Bug 17780 + def test_super_method_module_alias + m = Module.new do + def foo + end + alias :f :foo + end + + method = m.instance_method(:f) + super_method = method.super_method + assert_nil(super_method) + end + def rest_parameter(*rest) rest end |