From: merch-redmine@... Date: 2021-05-31T16:09:19+00:00 Subject: [ruby-core:104119] [Ruby master Bug#17887] Missed constant lookup after prepend Issue #17887 has been updated by jeremyevans0 (Jeremy Evans). Eregon (Benoit Daloze) wrote in #note-4: > jeremyevans0 (Jeremy Evans) wrote in #note-3: > > This is because unlike method tables, constant tables are not moved to origin classes. > > Do we know if this was somehow intentional or more like an oversight/incorrect optimization? I would think the latter. That I do not know. Most of the talk when prepend was added was about method lookup, but the same issues apply to constant lookup. > > This behavior has been present since origin classes were added in Ruby 2.0. > > Weren't origin classes introduced at the same time than `prepend`, specifically to implement `prepend`? Yes. ---------------------------------------- Bug #17887: Missed constant lookup after prepend https://bugs.ruby-lang.org/issues/17887#change-92292 * Author: bjfish (Brandon Fish) * Status: Open * Priority: Normal * ruby -v: 2.6.x-3.0.x * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- **Description** The following shows that the constant lookup from B does not find the constant in the prepended M module. I would expect this lookup to behave like "B.include M" which does print the constant from module M. **Example** ``` ruby module M FOO = 'm' end class A FOO = 'a' end class B < A def foo FOO end end b = B.new p b.foo A.prepend M p b.foo ``` **Expected Result** ``` "a" "m" ``` **Actual Result** ``` "a" "a" ``` -- https://bugs.ruby-lang.org/ Unsubscribe: