mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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:de097fbe5f
de48e47ddf
This commit is contained in:
parent
0d6263bd41
commit
c5c0bb5afc
Notes:
git
2025-04-10 08:20:48 +00:00
9 changed files with 26 additions and 98 deletions
7
class.c
7
class.c
|
@ -1004,9 +1004,8 @@ 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_const_set(rb_cObject, id, klass);
|
||||
rb_class_inherited(super, klass);
|
||||
rb_const_added(klass, id);
|
||||
|
||||
return klass;
|
||||
}
|
||||
|
@ -1044,10 +1043,8 @@ 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_const_set(outer, id, klass);
|
||||
rb_class_inherited(super, klass);
|
||||
rb_const_added(outer, id);
|
||||
|
||||
return klass;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue