From fd95a1805922d9fbe65e6f4c08609c7eac10b723 Mon Sep 17 00:00:00 2001 From: NAKAMURA Usaku Date: Mon, 31 May 2021 23:01:45 +0900 Subject: merge revision(s) d8a13e504992a45d52063f7c925408d7aad3595a: [Backport #17780] [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. --- proc.c | 2 +- test/ruby/test_method.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) --- proc.c | 2 +- test/ruby/test_method.rb | 13 +++++++++++++ version.h | 6 +++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/proc.c b/proc.c index d11d167f70..0c8889f04b 100644 --- a/proc.c +++ b/proc.c @@ -3045,7 +3045,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 0f0807af9d..03a6c560e6 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -1144,6 +1144,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 diff --git a/version.h b/version.h index fd537b7a30..66b31aad95 100644 --- a/version.h +++ b/version.h @@ -2,11 +2,11 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 4 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 185 +#define RUBY_PATCHLEVEL 186 #define RUBY_RELEASE_YEAR 2021 -#define RUBY_RELEASE_MONTH 4 -#define RUBY_RELEASE_DAY 16 +#define RUBY_RELEASE_MONTH 5 +#define RUBY_RELEASE_DAY 31 #include "ruby/version.h" -- cgit v1.2.3