False error: an anonymous subclass (new Anon() {}) does not get the state of the constructor it calls
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 69/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Java
- Star
- 71
- Fork
- 37
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 46
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của liquid-java/liquidjava
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
liquid-java/liquidjava#443 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug real-world-finding
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
liquid-java/liquidjava#395 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
liquid-java/liquidjava#373 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug error messages
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
liquid-java/liquidjava#471 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug error messages
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
liquid-java/liquidjava#469 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của liquid-java/liquidjava
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
objectionary/lints#1640 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
openhab/openhab-addons#22168 ·
Maintainer thường phản hồi trong vòng 1 ngày