From: "byroot (Jean Boussier) via ruby-core" Date: 2024-11-28T11:55:13+00:00 Subject: [ruby-core:120041] [Ruby master Feature#20912] Move warning when redefining object_id to __id__ Issue #20912 has been updated by byroot (Jean Boussier). > It seems used a lot, yes: I meant in context where it is called on an unknown object where `object_id` may have been redefined and cause the "serious problem" the warning hints at. I've dealt with tons of meta-programing messes over the last decade, I don't remember a case where `object_id` was involved. Skimming over these code sample I mostly see code that is just meant to use `equal?` instead, and some small snipets to showcase whether the object is similar etc. ---------------------------------------- Feature #20912: Move warning when redefining object_id to __id__ https://bugs.ruby-lang.org/issues/20912#change-110778 * Author: jhawthorn (John Hawthorn) * Status: Open ---------------------------------------- Currently if you create a class and redefine or remove either `object_id` or `__send__` it will issue a warning. There's no such warning on `__id__`. ``` ��� ruby -we 'class << Object.new; def object_id = 1; end' -e:1: warning: redefining `object_id' may cause serious problems ��� ruby -we 'class << Object.new; def __id__ = 1; end' ��� ``` It makes sense that there's no warning on `send`, because we expect `__send__` to be the method reliably available. `__send__` is on `BasicObject`, `send` is only on `Kernel`. This seems a little inconsistent that `object_id` warns while `__id__` does not warn. `__id__` is the equivalent to `__send__` as it's also on `BasicObject`, where `object_id` is only on `Kernel`. This may be a more obvious problem in Ruby 3.4.0 as commit:cffd380390967d17899fde0a81f5151ae6ddd076 makes the warning print in more cases. I propose we change this warning to be emitted only when `__id__` is redefined and not when `object_id` is redefined: **Proposed behaviour:** ``` ��� ruby -we 'class << Object.new; def object_id = 1; end' ��� ruby -we 'class << Object.new; def __id__ = 1; end' -e:1: warning: redefining `__id__' may cause serious problems ��� ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/