Ensure AttrContext.returnResult's checkContext is set to Check.basicHandler in javac's Scopes, to avoid it throwing exceptions.#8016
Merged
lahodaj merged 1 commit intoapache:masterfrom Dec 5, 2024
Conversation
…andler in javac's Scopes, to avoid it throwing exceptions.
dbalek
approved these changes
Dec 4, 2024
This file contains hidden or 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
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.
Consider this code, with a code completion invocation:
invoke the code completion at the marked place, and select the "test(Void p) - override" option. Nothing will happen, nothing will added to the source code.
The reason is this:
Scopetaken at the place of the cursor. TheScope'sEnv<AttrContext>has areturnResultfilled, and thisreturnResulthas acheckContextthat throws exceptions. This is part of method overload resolution in javac.GeneratorUtilities.createOverridingMethod, attempting to create the method.createOverridingMethodwill try to parse&attribute code like:in the context of the above
Scope. But thereturnstatement here does not match the expected return type from theScope, and so it will go to thecheckContext, and fail with the exception.This is a bit tricky, as a) the
Scopehere is used in a bit unintended way; b) many of the fields and types responsible for this are package private.The proposal in this PR is to replace the
checkContextin thereturnResultwith the default value (Check.basicHandler). That should, hopefully, solve this and any other similar problems.