diff options
author | Xavier Noria <[email protected]> | 2025-04-08 22:29:05 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-04-10 10:20:31 +0200 |
commit | c5c0bb5afcbbc054c9e8f4e4b9209253d42f7326 () | |
tree | 358f37c3f96a62b67b54e8e0ded384c2555519b6 /variable.c | |
parent | 0d6263bd416338a339651fb97fe4d62701704c4b (diff) |
Restore the original order of const_added and inherited callbacks
Originally, if a class was defined with the class keyword, the cref had a const_added callback, and the superclass an inherited callback, const_added was called first, and inherited second. This was discussed in https://bugs.ruby-lang.org/issues/21143 and an attempt at changing this order was made. While both constant assignment and inheritance have happened before these callbacks are invoked, it was deemed nice to have the same order as in C = Class.new This was mostly for alignment: In that last use case things happen at different times and therefore the order of execution is kind of obvious, whereas when the class keyword is involved, the order is opaque to the user and it is up to the interpreter. However, soon in https://bugs.ruby-lang.org/issues/21193 Matz decided to play safe and keep the existing order. This reverts commits: de097fbe5f3df105bd2a26e72db06b0f5139bc1a de48e47ddf78aba02fd9623bc7ce685540a10743
Notes: Merged: https://.com/ruby/ruby/pull/13085
-rw-r--r-- | variable.c | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -2624,6 +2624,7 @@ rb_autoload(VALUE module, ID name, const char *feature) } static void const_set(VALUE klass, ID id, VALUE val); struct autoload_arguments { VALUE module; @@ -2732,7 +2733,7 @@ rb_autoload_str(VALUE module, ID name, VALUE feature) VALUE result = rb_mutex_synchronize(autoload_mutex, autoload_synchronized, (VALUE)&arguments); if (result == Qtrue) { - rb_const_added(module, name); } } @@ -3603,8 +3604,8 @@ set_namespace_path(VALUE named_namespace, VALUE namespace_path) RB_VM_LOCK_LEAVE(); } -void -rb_const_added(VALUE klass, ID const_name) { if (GET_VM()->running) { VALUE name = ID2SYM(const_name); @@ -3680,16 +3681,10 @@ const_set(VALUE klass, ID id, VALUE val) } void -rb_const_set_raw(VALUE klass, ID id, VALUE val) -{ - const_set(klass, id, val); -} - -void rb_const_set(VALUE klass, ID id, VALUE val) { const_set(klass, id, val); - rb_const_added(klass, id); } static struct autoload_data * |