False error: an anonymous subclass (new Anon() {}) does not get the state of the constructor it calls

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

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
69/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
devtools

調査の方向性

Start by reading RefinementTypeChecker.visitCtNewClass and comparing it with visitCtConstructorCall, then inspect AuxStateHandler.onlySuperCall and delegatedConstructorState. Use the minimal reproducer in the issue to verify the behavior; it is done when the anonymous subclass with no instance or field initializer inherits the constructor's ready state and verification passes.

索引モデルが issue の本文から書いたものです。

説明

bug

Impact: an object created as an anonymous subclass (new Anon() {}) has an unknown state, so the first state-refined call on it is a false error. The hint then suggests the very constructor that was called.

Minimal reproducer

import liquidjava.specification.StateRefinement;
import liquidjava.specification.StateSet;

@StateSet({"fresh", "ready"})
public abstract class Anon {
    @StateRefinement(to = "ready(this)")
    public Anon() {}

    @StateRefinement(from = "ready(this)", to = "fresh(this)")
    public void use() {}

    static void ok() {
        Anon a = new Anon() {};
        a.use();   // the constructor made a ready
    }
}

Expected: Correct! Passed Verification.; the anonymous class has no initializer, so a is in the state Anon() gives (ready).

Actual (main @ 0053074e):

State Refinement Error: found true but expected ready(a⁶)
12 |     static void ok() {
13 |         Anon a = new Anon() {};
14 |         a.use();   // the constructor made a ready
   |         ^^^^^^^^
15 |     }
16 | }

Hints:
  - The state of a is unknown here. To get it to ready, use: new Anon()

Control: with a non-abstract Anon and Anon a = new Anon();, it verifies.

Cause. RefinementTypeChecker.visitCtNewClass only calls super.visitCtNewClass. Unlike visitCtConstructorCall, it never calls mfc.getConstructorInvocationRefinements, so the super constructor's to state is not applied. AuxStateHandler.delegatedConstructorState also returns empty for every CtNewClass, because the anonymous body may change the state. Applying the super constructor's state when the anonymous body has no instance initializer or field initializer (the same condition AuxStateHandler.onlySuperCall uses) would fix it.

🤖 Generated with Claude Code

主要言語
Java
スター
71
フォーク
37
平均マージ
1日 19時間
マージ済み PR(30日)
46

環境構築

はじめの一歩

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

liquid-java/liquidjava のほかの issue

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

似ている issue

Java の issue をもっと見る

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

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