eclipse-jdt / eclipse-jdt/eclipse.jdt.core
DiagnoseParser emits spurious "insert ':: IdentifierOrNew' to complete Expression" alongside the real "insert ';'" recovery
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 49
Description
### Summary
When a statement is missing its trailing semicolon and ends in a bare `Name`, `DiagnoseParser` reports **two** `ParsingErrorInsertToComplete` (id `1610612976`) problems at the same location: the correct `insert ";" to complete Statement`, plus a spurious `insert ":: IdentifierOrNew" to complete Expression`. The second message is confusing because it suggests the user intended a method reference (`name::foo` / `name::new`) when they simply forgot a `;`.
### Steps to reproduce
```java
public class Dog {
String name;
int age;
String color;
public Dog(String name, int age, String color) {
this.name = name;
this.age = age;
this.color = color // missing ';'
}
}
```
### Actual diagnostics (both at `color`, both id 1610612976)
- `Syntax error, insert ":: IdentifierOrNew" to complete Expression`
- `Syntax error, insert ";" to complete Statement`
### Expected
Only the actionable `insert ";" to complete Statement` should be reported. The trailing `Name` is a valid prefix of a `ReferenceExpression` (`Name '::' IdentifierOrNew`, see [java.g](https://github.com/eclipse-jdt/eclipse.jdt.core/blob/master/org.eclipse.jdt.core.compiler.batch/grammar/java.g)), so the recovery engine's insertion phase scores the method-reference completion as a viable repair and emits it next to the semicolon fix.
### Notes
Same class of over-eager `DiagnoseParser` recovery as #1734 (spurious string-template recovery). Originally surfaced via VS Code: microsoft/vscode-java-pack#89.
### Environment
- Reproduces in current ECJ / Eclipse JDT and in `redhat.java` (JDT-LS).
Contributor guide
Research direction
Reproduce the diagnostic with the Java example, then read java.g and the DiagnoseParser insertion phase to see why ReferenceExpression recovery is emitted alongside the semicolon repair. Done means the missing-semicolon case reports only insert ";" to complete Statement, with coverage for the reported input.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100