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

オープン
#500 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
45

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

liquid-java/liquidjava のほかの issue

liquid-java/liquidjava の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。