summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-03-20 17:25:15 +0100
committerJean Boussier <[email protected]>2025-03-20 18:18:11 +0100
commitde097fbe5f3df105bd2a26e72db06b0f5139bc1a (patch)
tree3a3fa5499e0ec9e6eba24fb8dfc62127dd373a89 /class.c
parenta51364f54b644ba2d98779f0af8c7203822d9a31 (diff)
Trigger `inherited` and `const_set` callbacks after const has been defined
[Misc #21143] [Bug #21193] The previous change caused a backward compatibility issue with code that called `Object.const_source_location` from the `inherited` callback. To fix this, the order is now: - Define the constant - Invoke `inherited` - Invoke `const_set`
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12956
Diffstat (limited to 'class.c')
-rw-r--r--class.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/class.c b/class.c
index 5d13cbaf7d..9716aab78c 100644
--- a/class.c
+++ b/class.c
@@ -1004,8 +1004,9 @@ rb_define_class(const char *name, VALUE super)
}
klass = rb_define_class_id(id, super);
rb_vm_register_global_object(klass);
+ rb_const_set_raw(rb_cObject, id, klass);
rb_class_inherited(super, klass);
- rb_const_set(rb_cObject, id, klass);
+ rb_const_added(klass, id);
return klass;
}
@@ -1043,8 +1044,10 @@ rb_define_class_id_under_no_pin(VALUE outer, ID id, VALUE super)
}
klass = rb_define_class_id(id, super);
rb_set_class_path_string(klass, outer, rb_id2str(id));
+
+ rb_const_set_raw(outer, id, klass);
rb_class_inherited(super, klass);
- rb_const_set(outer, id, klass);
+ rb_const_added(outer, id);
return klass;
}