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

Ouverte
#470 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
69/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
java
Domaine
devtools

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
Java
Étoiles
71
Forks
37
Merge moyen
1 j 19 h
PR mergées (30 j)
46

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de liquid-java/liquidjava

Toutes les issues de liquid-java/liquidjava

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.