vscode-java-debug icon indicating copy to clipboard operation
vscode-java-debug copied to clipboard

switch exhaustiveness check not working within deconstruction pattern

Open RedIODev opened this issue 3 years ago • 0 comments

Build fails on missing default case, even though switch is exhaustive.

Environment
  • Operating System: Windows 10
  • JDK version: 19
  • Visual Studio Code version: 1.73.1
  • Java extension version: 1.12.0
  • Java Debugger extension version: 0.46.0
Steps To Reproduce

make (exhaustive) switch expression with nested deconstruction pattern build fails -> "Add default case"

Example:

package dev.redio;

import static dev.redio.Main.Activity.*;

public class Main {

    public static void main(String[] args) {
        record Pair(boolean weekend, Activity activity) {}
        var pair = new Pair(true, new Sleeping(8));
        var msg = switch (pair) {   // <- A switch expression should have a default caseJava(1073743531)
            case Pair(boolean b, Sleeping s) -> "3";
            case Pair(boolean b, Skiing s) -> "4";
            case Pair(boolean b, Coding c) -> "5";
        };
        
        System.out.println(msg);
    }

    sealed interface Activity {
        record Sleeping(int hours) implements Activity {}
        record Skiing(String resort) implements Activity {}
        record Coding() implements Activity {}
    }
    
}
Current Result

Build Error (A switch expression should have a default caseJava(1073743531))

Expected Result

Build Success(Switch is exhaustive since all nested deconstruction possibilities are covered)

Additional Informations

Compiles with pure javac without errors Intended and correct syntax confirmed by member of development team of the feature.

RedIODev avatar Nov 14 '22 21:11 RedIODev