eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
164 stars 130 forks source link

[23] ECJ rejects a default case when it shouldn't #2933

Closed jarthana closed 1 month ago

jarthana commented 1 month ago

Here's the test:

public class X {
    public static float byteToFloat(Byte a) {
        return switch (a) {
            case float y -> y;
            default -> 2;
        };
    }
}

ECJ report on the default that Switch case cannot have both unconditional pattern and default label". Looks like somewhere we are omitting the fact that the float is not matching Byte.

mpalat commented 1 month ago

with the latest code the error had gone but the run-time results were wrong - it was branching to default- this gets corrected via the pr #2944

stephan-herrmann commented 1 month ago

Resolved by https://github.com/eclipse-jdt/eclipse.jdt.core/pull/2944

I made a private note that we still don't have a test case that systematically tests unbox-then-widen in pattern switches. To be added when at leisure.