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

Đang mở
#470 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
devtools

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ả

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

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của liquid-java/liquidjava

Tất cả issue của liquid-java/liquidjava

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.