Open Madjosz opened 6 months ago
Interesting.
The parse tree for the method comes out to be:
private Predicate<String> matches() {
return (<no type> s) -> {
List<Object> results = List.of();
return IntStream.range(0, 10).allMatch(results.get(i)."");
};
}
See the "" at the end of the return statement inside the lambda!
Basically we have parsed a string template expression where none existed. I suspect DiagnoseParser's black magic having a finger in the pie
Yep. DiagnoseParser inserts a ""
at the syntax error site and then during recovery we see a String template. This itself is not the problem per se - org.eclipse.jdt.core.dom.ASTConverter.convert(Expression)
is lacking a case for StringTemplate
s and returns null
which then results in IAE.
We may want to steer the DiagnoseParser from inserting ""
into the Recovery Scanner's input stream - otherwise code completion may break as reported above
Latest build of Eclipse (I20240205-1800) does not throw anymore and shows
Syntax error on token ".", StringLiteral expected after this token
when hovering the last .
and on results.get(i)
it shows
String Template is a preview feature and disabled by default. Use --enable-preview to enable
This is better (as it does not hard-fail the build) but not at all what this code is about. Content assist also suggests List
methods after last .
but that might be due to the missing declaration of the i
variable and thus the compiler not being able to find a suitable method.
aa1a02d82b31a8ecfdd7aed71ecd79178299735e fixed the errors appearing in the Error Log view and I would consider this issue fixed. The spurious recovery of String template might be worth its own issue but there might already be enough issues about String templates so we could revisit this behaviour when the implementation is more mature.
With the following code three messages in the Error Log View pop up
It also messes with postfix completions on the trailing
.
after theget()
call:System information
Eclipse SDK Version: 2024-03 (4.31) Build id: I20231207-1800
openjdk 21 2023-09-19 LTS OpenJDK Runtime Environment Temurin-21+35 (build 21+35-LTS) OpenJDK 64-Bit Server VM Temurin-21+35 (build 21+35-LTS, mixed mode, sharing)