Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Module#ancestors order in recursive constant lookup #4585

Merged
merged 1 commit into from
Jun 30, 2021

Conversation

XrXr
Copy link
Member

@XrXr XrXr commented Jun 17, 2021

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.

[Bug #17887]

@jeremyevans
Copy link
Contributor

This is much simpler than my approach in #4538. I also think you are correct about the handling of the inherit argument, since that is more consistent with how method_defined? works. Great work! As long as this passes CI, I'll close #4538.

@jeremyevans jeremyevans requested a review from nobu June 18, 2021 01:09
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.

[Bug #17887]
@nobu nobu merged commit 3dd3ea0 into ruby:master Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants