eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
168 stars 132 forks source link

[Switch Expressions] Poor quality diagnostics #3289

Open srikanth-sankaran opened 2 weeks ago

srikanth-sankaran commented 2 weeks ago

This program generates two errors:

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);
    }
}
srikanth-sankaran commented 2 weeks ago

jaavc simply says "X.java:9: error: ';' expected"