False error: an anonymous subclass (new Anon() {}) does not get the state of the constructor it calls
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 69/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Java
- Stelle
- 71
- Fork
- 37
- Merge medio
- 1g 19h
- PR unite (30g)
- 46
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di liquid-java/liquidjava
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
liquid-java/liquidjava#443 ·
I maintainer di solito rispondono entro 2 giorni
-
bug real-world-finding
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
liquid-java/liquidjava#395 ·
I maintainer di solito rispondono entro 2 giorni
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
liquid-java/liquidjava#373 ·
I maintainer di solito rispondono entro 2 giorni
-
bug error messages
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
liquid-java/liquidjava#471 ·
I maintainer di solito rispondono entro 2 giorni
-
bug error messages
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
liquid-java/liquidjava#469 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di liquid-java/liquidjava
Issue simili
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
objectionary/lints#1640 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
openhab/openhab-addons#22168 ·
I maintainer di solito rispondono entro 1 giorno