Fix: Make sure compact constructor assignments resolve correctly to the fields#6687
Closed
Luro02 wants to merge 1 commit intoINRIA:masterfrom
Closed
Fix: Make sure compact constructor assignments resolve correctly to the fields#6687Luro02 wants to merge 1 commit intoINRIA:masterfrom
Luro02 wants to merge 1 commit intoINRIA:masterfrom
Conversation
Contributor
Author
|
Further investigation: According to the JLS a compact constructor body like MyRecord {
string = string + "!!!";
}does never assign to a component field (= the field of the record) of the record, and here in explicit words:
So the current behavior seems to be correct, even though it is confusing... |
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.
While updating my code to newer spoon versions, I observed that in code like:
The left side of the assignment isn't a field write anymore. It is currently a
CtVariableWrite.Then I thought, okay, if the
getDeclarationresolves to the field anyway, it wouldn't be a big problem, but unfortunately it resolves to the implicit parameter, which is wrong.For example here is how IntelliJ resolves it:


When looking at this, it seems like there isn't supposed to be a parameter? Both references resolve to the field? Maybe it is just a visual thing...
I added an explicit test case for what is failing and wrote a minor surface-level patch to address this issue, but I am not very familiar with the JDT code or how the tree builder works. I think there might be a better place to resolve this issue, or is it a regression introduced by JDT?
The root cause of this seems to be PR #6316.