summaryrefslogtreecommitdiff
path: root/vm_method.c
diff options
context:
space:
mode:
authorKoichi Sasada <[email protected]>2024-10-31 19:08:05 +0900
committerKoichi Sasada <[email protected]>2024-11-01 11:50:00 +0900
commit783dde2159a3689ad2d3ef6b7d0005a7cf80adba (patch)
tree1f7392e25cc008826be38a5736da4633a6c5fe3a /vm_method.c
parenta8c32ace459d56501c03e360da7c315d5b91142a (diff)
`alias` should not set `defined_class` for Modules
`me->defined_class` should be 0 for method entries of Modules. This patch checks this condition and fix https://github.com/ruby/ruby/pull/11965#issuecomment-2448291790
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11968
Diffstat (limited to 'vm_method.c')
-rw-r--r--vm_method.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/vm_method.c b/vm_method.c
index 1a6e965e44..120e8b0563 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -2332,7 +2332,13 @@ rb_alias(VALUE klass, ID alias_name, ID original_name)
alias_me = method_entry_set(target_klass, alias_name, orig_me, visi, orig_me->owner);
RB_OBJ_WRITE(alias_me, &alias_me->owner, target_klass);
- RB_OBJ_WRITE(alias_me, &alias_me->defined_class, orig_me->defined_class);
+
+ if (RB_TYPE_P(target_klass, T_MODULE)) {
+ // defined_class should not be set
+ }
+ else {
+ RB_OBJ_WRITE(alias_me, &alias_me->defined_class, orig_me->defined_class);
+ }
}
}