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.
This is because unlike method tables, constant tables are not moved to origin classes. This behavior has been present since origin classes were added in Ruby 2.0. I submitted a pull request to work around this: https://github.com/ruby/ruby/pull/4538
I agree it should be a bug. @nobu (Nobuyoshi Nakada), could you review @jeremyevans's patch? I'd like to see if the fix causes any compatibility issue.
Use Module#ancestors order in recursive constant lookup
Before this commit, const_get with inherit=true and constant lookup
expressions searched the ancestors of the starting point in an order
different from starting_point.ancestors.
Items in the ancestry list introduced through prepend were searched
after searching the module they were prepended into. This oddity allowed
for situations where constant lookups gave different results even though starting_point.ancestors is the same.
Do the lookup in the same order as starting_point.ancestors by
skipping classes and modules that have an origin iclass. The origin
iclass is in the super chain after the prepended modules.
Note that just like before this commit, the starting point of the
constant lookup is always the first item that we search, regardless of
the presence of any prepended modules.