aboutsummaryrefslogtreecommitdiffstats
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-08-27 08:37:03 -0700
committerGitHub <noreply@github.com>2020-08-27 08:37:03 -0700
commitc60aaed1856b2b6f90de0992c34771830019e021 (patch)
treed0580ff9dd4e435554be13ec19dc9cfba48a39b7 /vm_insnhelper.c
parentf41bd0d7087eac1920188e055cc1f4e79a6a6047 (diff)
downloadruby-c60aaed1856b2b6f90de0992c34771830019e021.tar.gz
Fix Method#super_method for aliased methods
Previously, Method#super_method looked at the called_id to determine the method id to use, but that isn't correct for aliased methods, because the super target depends on the original method id, not the called_id. Additionally, aliases can reference methods defined in other classes and modules, and super lookup needs to start in the super of the defined class in such cases. This adds tests for Method#super_method for both types of aliases, one that uses VM_METHOD_TYPE_ALIAS and another that does not. Both check that the results for calling super methods return the expected values. To find the defined class for alias methods, add an rb_ prefix to find_defined_class_by_owner in vm_insnhelper.c and make it non-static, so that it can be called from method_super_method in proc.c. This bug was original discovered while researching [Bug #11189]. Fixes [Bug #17130]
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index e6228fb466..f1c293a50a 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -2673,8 +2673,8 @@ vm_call_bmethod(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_c
return vm_call_bmethod_body(ec, calling, cd, argv);
}
-static VALUE
-find_defined_class_by_owner(VALUE current_class, VALUE target_owner)
+MJIT_FUNC_EXPORTED VALUE
+rb_find_defined_class_by_owner(VALUE current_class, VALUE target_owner)
{
VALUE klass = current_class;
@@ -2702,7 +2702,7 @@ aliased_callable_method_entry(const rb_callable_method_entry_t *me)
const rb_callable_method_entry_t *cme;
if (orig_me->defined_class == 0) {
- VALUE defined_class = find_defined_class_by_owner(me->defined_class, orig_me->owner);
+ VALUE defined_class = rb_find_defined_class_by_owner(me->defined_class, orig_me->owner);
VM_ASSERT(RB_TYPE_P(orig_me->owner, T_MODULE));
cme = rb_method_entry_complement_defined_class(orig_me, me->called_id, defined_class);