summaryrefslogtreecommitdiff
path: root/vm_method.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-02-18 15:22:37 -0800
committerJeremy Evans <code@jeremyevans.net>2021-03-16 12:10:11 -0700
commit58660e943488778563b9e41005a601e9660ce21f (patch)
treef2da25d960ea4ebab02911ede6a3ff4e00ec2363 /vm_method.c
parent756e8a2cf3424b9a3eb9dde4a01325cba21a7e81 (diff)
Skip refined method when exporting methods with changed visibility
Previously, attempting to change the visibility of a method in a singleton class for a class/module that is prepended to and refined would raise a NoMethodError. Fixes [Bug #17519]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4200
Diffstat (limited to 'vm_method.c')
-rw-r--r--vm_method.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/vm_method.c b/vm_method.c
index 2573e708ba..0f25c514a8 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -968,7 +968,7 @@ rb_method_entry_at(VALUE klass, ID id)
}
static inline rb_method_entry_t*
-search_method(VALUE klass, ID id, VALUE *defined_class_ptr)
+search_method0(VALUE klass, ID id, VALUE *defined_class_ptr, bool skip_refined)
{
rb_method_entry_t *me = NULL;
@@ -977,7 +977,9 @@ search_method(VALUE klass, ID id, VALUE *defined_class_ptr)
for (; klass; klass = RCLASS_SUPER(klass)) {
RB_DEBUG_COUNTER_INC(mc_search_super);
if ((me = lookup_method_table(klass, id)) != 0) {
- break;
+ if (!skip_refined || me->def->type != VM_METHOD_TYPE_REFINED) {
+ break;
+ }
}
}
@@ -989,6 +991,12 @@ search_method(VALUE klass, ID id, VALUE *defined_class_ptr)
return me;
}
+static inline rb_method_entry_t*
+search_method(VALUE klass, ID id, VALUE *defined_class_ptr)
+{
+ return search_method0(klass, id, defined_class_ptr, false);
+}
+
static rb_method_entry_t *
search_method_protect(VALUE klass, ID id, VALUE *defined_class_ptr)
{
@@ -1376,7 +1384,7 @@ rb_export_method(VALUE klass, ID name, rb_method_visibility_t visi)
VALUE defined_class;
VALUE origin_class = RCLASS_ORIGIN(klass);
- me = search_method(origin_class, name, &defined_class);
+ me = search_method0(origin_class, name, &defined_class, true);
if (!me && RB_TYPE_P(klass, T_MODULE)) {
me = search_method(rb_cObject, name, &defined_class);