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

Abierto
#470 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
69/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java
Área
devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Java
Estrellas
71
Forks
37
Merge medio
1 d 19 h
PR fusionados (30 d)
46

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de liquid-java/liquidjava

Todos los issues de liquid-java/liquidjava

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.