eclipse-jdt / eclipse-jdt/eclipse.jdt.core

[Switch Expressions] Poor quality diagnostics

Open
#3,289 1 comment 0 reactions 1 assignee Claimed by @srikanth-sankaran View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

This program generates two errors:

* Syntax error, insert ";" to complete LocalVariableDeclarationStatement
* Syntax error on token "yield", AssignmentOperator expected after this token

```
public class X {
public static void main(String[] args) {
Object x = "Hello";
String j = switch (x) {
case String s : yield "String";
default : { System.out.println();
yield "Default";
}
}
}
}
```

The second one is not helpful and head scratch inducing.

(2) This program generates: `C cannot be resolved or is not a field` which is not quite the case even though the error is valid.

```
public class X {
enum E1 {
A;
}

enum E2 {
B;
}

public static final int C = 42;

public static void main(String[] args) {

}
void foo(E1 e1) {
switch (e1) {
case A :
case C :
}

System.out.println(C);
}
}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.