microsoft / microsoft/vscode-java-debug

switch exhaustiveness check not working within deconstruction pattern

未关闭
#1,260 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

ai-triaged bug compile
主要语言
TypeScript
星标
591
派生
429
平均合并
1 天 9 小时
30 天内合并 PR
19

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

在列出的 VS Code 和 Java 环境中复现 issue 中的嵌套解构模式 switch,并将扩展的诊断结果与纯 javac 进行比较。追踪“A switch expression should have a default case”诊断在哪里产生。完成标准是:穷尽示例能够在没有该诊断的情况下构建,同时真正非穷尽的 switch 仍然报告该诊断。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, vscode
领域
devtools
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。