diff options
author | Jean Boussier <[email protected]> | 2025-03-20 17:25:15 +0100 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-03-20 18:18:11 +0100 |
commit | de097fbe5f3df105bd2a26e72db06b0f5139bc1a (patch) | |
tree | 3a3fa5499e0ec9e6eba24fb8dfc62127dd373a89 /class.c | |
parent | a51364f54b644ba2d98779f0af8c7203822d9a31 (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.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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; } |