In a second `for…of` loop with the same loop variable, specs that use `_x_idx2` get an unknown type
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 65/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- compilers
Línea de trabajo
Start with the forof case in tools/src/resolve.ts, where the loop index is bound for specs, and compare it with the transform code that numbers repeated loops per function as _x_idx, _x_idx2, and so on. The two counters must agree so that a //@ invariant naming _x_idx2 resolves to type nat. Done when the reproduction emits Dafny that verifies and a regression test checks the second loop's counter name and type.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Problem
SPEC.md §4.1 ("For-of loops") says that when several for…of loops use the same variable name, the generated index is disambiguated as _id_idx, _id_idx2, and so on. Resolve binds the index in the loop's environment so that specs such as //@ invariant can refer to it (tools/src/resolve.ts, the forof case). But resolve and transform name the counter separately: resolve gives every such loop's counter the name _x_idx, while transform numbers repeated loops per function and emits _x_idx2 for the second. A spec in the second loop that writes _x_idx2 therefore names a variable resolve never bound, and it gets an unknown type.
The unknown type matters wherever lowering depends on the type. In real arithmetic the counter is not converted with as real, and Dafny rejects the output. No false proof results, but a documented spec does not verify.
Reproduced on upstream main at add6ccd (0.6.10).
Reproduction
export function halfTwice(xs: number[]): number {
let n = 0;
for (const x of xs) {
n = n + 1;
}
let m = 0;
for (const x of xs) {
//@ invariant m * 1.5 === _x_idx2 * 1.5
m = m + 1;
}
return n + m;
}
emits, for the second loop:
var i_x_idx2 := 0;
while i_x_idx2 < |xs|
invariant (i_x_idx2 <= |xs|)
invariant (((m as real) * 1.5) == (i_x_idx2 * 1.5))
dafny verify reports arguments must have comparable types (got real and int) and type of right argument to * (real) must agree with the result type (int).
The same invariant in a function with one loop, //@ invariant m * 1.5 === _x_idx * 1.5, emits ((i_x_idx as real) * 1.5) and verifies.
Expected
Resolve binds the same counter name that transform emits for each loop, so _x_idx2 in the second loop has type nat and lowers like _x_idx in the first. Generating the name once in resolve, recording it on the forof statement, and having transform reuse it removes the disagreement. robertpenner/LemmaScript#37 does this; with it, the reproduction emits ((i_x_idx2 as real) * 1.5) and verifies.
Acceptance criteria
- The reproduction generates Dafny that verifies.
- A regression test checks that resolve gives the second loop's counter the name
_x_idx2with typenat, and that an invariant using it verifies.
- Lenguaje dominante
- TypeScript
- Estrellas
- 113
- Forks
- 13
- Merge medio
- 15 h 35 min
- PR fusionados (30 d)
- 56
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de midspiral/LemmaScript
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
midspiral/LemmaScript#355 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
In a pure function body, a `const` declared inside an `if` branch stays in scope after the `if`, so a false `ensures` can verifyPosiblemente ocupada @namin la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
midspiral/LemmaScript#362 ·
Los mantenedores suelen responder en 1 día
-
A `const` or `let` inside a bare `{ }` block stays in scope after the block, so a false `ensures` can verifyPosiblemente ocupada @namin la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 15/100
midspiral/LemmaScript#361 ·
Los mantenedores suelen responder en 1 día
-
A closure declared before a same-name `const` or `let` in its block reads the outer variable, so a false `ensures` can verifyPosiblemente ocupada @namin la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 18/100
midspiral/LemmaScript#360 ·
Los mantenedores suelen responder en 1 día
-
An assignment used as an expression, such as `(x = 7);` or `const y = (x = 7)`, is extracted as an equality test, so a false `ensures` can verifyPosiblemente ocupada @namin la tomó hoy. Abierto
Dificultad 3/5 Medio día Aptitud para principiantes 30/100
midspiral/LemmaScript#356 · 1 reacción ·
Los mantenedores suelen responder en 1 día
Todos los issues de midspiral/LemmaScript
Issues similares
-
bug done
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
neavo/LinguaGacha#1124 ·
Los mantenedores suelen responder en 1 día
-
[fullsend] E2E: backstage-microsoft-auth — catalogQuery missing error handler for network errorsPosiblemente ocupada @fullsend-ai-coder la tomó hoy. Abiertoe2e-failure ready-to-code
Dificultad 2/5 Menos de una hora Aptitud para principiantes 78/100
redhat-developer/rhdh-plugin-export-overlays#4821 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
brylie/mission-island#225 ·
Los mantenedores suelen responder en 1 día
-
status/need-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
google-gemini/gemini-cli#30412 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día