False error: an anonymous subclass (new Anon() {}) does not get the state of the constructor it calls
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 69/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Java
- Sterne
- 71
- Forks
- 37
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 46
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus liquid-java/liquidjava
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
liquid-java/liquidjava#443 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
bug real-world-finding
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
liquid-java/liquidjava#395 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
liquid-java/liquidjava#373 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
bug error messages
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
liquid-java/liquidjava#471 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
bug error messages
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
liquid-java/liquidjava#469 ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in liquid-java/liquidjava
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Dans-Plugins/Medieval-Roleplay-Engine#396 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 6 Tagen
-
type: dependency-upgrade
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 70/100
spring-projects/spring-session#4156 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
quarkiverse/quarkus-langchain4j#3127 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
HotswapProjects/HotswapAgent#688 ·