-
Notifications
You must be signed in to change notification settings - Fork 423
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
Fix incorrect resolution of outer variable when method exists with the same name #25878
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mppf
changed the title
Issue 25551 2
Fix incorrect resolution of outer variable when method exists with the same name
Sep 4, 2024
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
Field declarations *can* refer to fields from the receiver scope (including parent class fields) --- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
benharsh
approved these changes
Sep 5, 2024
--- Signed-off-by: Michael Ferguson <[email protected]>
--- Signed-off-by: Michael Ferguson <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #25551
Resolves #22918
This PR adjusts the way the new scope resolver handles looking for matches for methods in order to resolve problems with incorrect matches to methods interfering with finding an outer variable, which is the problem that occurs in #25551.
What is going wrong in #25551 is that the new scope resolver is 1) looking for the innermost match (for an identifier) and 2) searching first for methods from the definition point of myComparator and its parents. The result is to find the unrelated
text
method instead of the outer variable.This PR resolves the problem by adjusting the scope resolution process to only consider methods that could be called when considering method receiver scopes.
Instead of pre-computing the receiver scopes and then checking these for methods, the lookup process now works with helper objects to call back into the scope resolution or full resolution process. There are two different helper objects for different purposes:
MethodLookupHelper
provides a way to access the scopes that should be checked for methods/fields and also provides a way to check if the receiver is applicableReceiverScopeHelper
provides a way to get aMethodLookupHelper
that corresponds to the receiver type for a particular method ID (and at that point, the scopes from theMethodLookupHelper
should be checked for applicable methods)There are two implementations of each of these -- one that uses simplified rules and works without types (for use with the new scope resolution, which is currently enabled in production) -- and one that uses the full type system.
Reviewed by @benharsh - thanks!