False error: an anonymous subclass (new Anon() {}) does not get the state of the constructor it calls
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
调研方向
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 内容生成。
描述
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 小时
- 30 天内合并 PR
- 46
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
liquid-java/liquidjava 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
liquid-java/liquidjava#443 ·
维护者通常 2 天内回复
-
bug real-world-finding
难度 2/5 1-3 小时 新手友好度 82/100
liquid-java/liquidjava#395 ·
维护者通常 2 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 65/100
liquid-java/liquidjava#373 ·
维护者通常 2 天内回复
-
bug error messages
难度 4/5 3-5 天 新手友好度 52/100
liquid-java/liquidjava#471 ·
维护者通常 2 天内回复
-
bug error messages
难度 3/5 1-2 天 新手友好度 68/100
liquid-java/liquidjava#469 ·
维护者通常 2 天内回复
查看 liquid-java/liquidjava 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
Dans-Plugins/Medieval-Roleplay-Engine#396 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
objectionary/lints#1640 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 72/100
virtualcell/vcell#2193 ·
维护者通常 1 天内回复