False error: a switch case on a library enum (e.g. DayOfWeek) does not know its label (Found shows #MONDAY_value)

未關閉
#500 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
java
領域
compilers

研究方向

Start by comparing how the analyzer translates enum constants in if conditions and switch case labels, especially for enums declared in JDK or library code; the issue gives a reproducing example using DayOfWeek. Make both translations represent the same constant consistently, or assign enum constants stable distinct values. Done means the example no longer reports a refinement error and the diagnostic does not expose #MONDAY_value.

由索引模型根據 Issue 內容生成。

描述

bug

Follow-up to #494 / #497. A case label of an enum declared outside the project (a JDK or library enum such as java.time.DayOfWeek) is not linked to the same constant used elsewhere, so the case's condition adds no information. Correct code is rejected, and the message shows an internal name.

@StateSet({"closed", "open"})
class Door {
    @StateRefinement(to = "closed(this)") Door() {}
    @StateRefinement(from = "closed(this)", to = "open(this)") void open() {}
    @StateRefinement(from = "open(this)", to = "closed(this)") void close() {}
}

class LibEnum {
    // Correct: the door is opened exactly on Mondays and closed exactly on Mondays
    static void monday(DayOfWeek day) {
        Door d = new Door();
        if (day == DayOfWeek.MONDAY)
            d.open();
        switch (day) {
            case MONDAY:
                d.close();
                break;
            default:
                break;
        }
    }
}

On the #497 branch (432a508c):

State Refinement Error: found day == #MONDAY_value ? open(d) : closed(d) but expected open(d)
25 |                 d.close();
Hints:
  - d can be in closed or open here, depending on the path taken, and no sequence of calls moves all of them to open. Make d reach this line in the same state on every path

Expected: no error, since inside case MONDAY the condition day == DayOfWeek.MONDAY holds. #MONDAY_value is an internal name users are not told about.

Enums declared in the project already work. Fix direction: translate library enum constants the same way in both the if condition and the case label (or give every enum constant a stable, distinct value), so case MONDAY adds day == DayOfWeek.MONDAY.

Not needed for the error-message study (no study exercise switches on a library enum).

主要語言
Java
星號
73
分支
38
平均合併
12 小時 32 分鐘
30 天內合併 PR
45

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

liquid-java/liquidjava 的其他 Issue

查看 liquid-java/liquidjava 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。