eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
156 stars 123 forks source link

[Sealed Types + Enhanced Switch] Incorrect diagnostic about switch not being exhaustive #2720

Open srikanth-sankaran opened 1 month ago

srikanth-sankaran commented 1 month ago

Reported here by @nlisker : https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2719#issuecomment-2232303720

I've just ran into what seems to be the same problem:

sealed interface I {

    enum E implements I {
        A, B, C;
    }
} 

class Test {

    void d(I i) {
        switch (i) { // error: An enhanced switch statement should be exhaustive; a default label expected
            case I.E.A -> {}
            case I.E.B -> {}
            case I.E.C -> {}
        }
    }
}

But there are no other valid cases (I must be an E, which must be A, B or C).

Didn't test with javac.

Version: 2024-06 (4.32) Build id: I20240601-0610