bug: Type of string concatenation is null #3075
Merged
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.
Hi!
I found out that Spoon returns null type for 2 or more concatenations of string literals.
For example:
String s = "one" + "two" + "three";
Spoon says that the type of "two" + "three" is null, but it's actually String.
I provided the test that demonstrates that.
Moreover, I'm sure that the problem is here:
spoon/src/main/java/spoon/support/compiler/jdt/ParentExiter.java
Lines 421 to 432 in f2ecd5d
We create a new
CtBinaryOperator
but do not set its type.So I tried to fix that by adding setType call:
op.setType((CtTypeReference) operator.getFactory().Type().STRING);
This fix works and type appears, but
AstParentConsistencyChecker
does not like it, becausesetType
sets parent of the reference toop
, so I'm getting:Do you have any ideas how to set the parent properly here?
Thanks.