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 verify
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 30/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- compilers
Línea de trabajo
Start in tools/src/extract.ts: the op === "=" branch in extractExpr (around line 516) emits a binop that later becomes ==, and desugarStmtExpr (around line 1350) does not unwrap a ParenthesizedExpression before checking for an assignment. Done means (x = 7); and const y = (x = 7); lower to an assignment or a source-positioned error, and the parenWholeAssign example no longer verifies. Note that pull request #363 is already open against this issue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Problem
When a JavaScript assignment appears in expression position, extract turns it into the IR's equality operator. (x = 7); and const y = (x = 7); therefore emit x == 7, the assignment disappears, and a false ensures verifies.
Reproduced on upstream main at 2ccd0a5 (0.6.11) with Dafny 4.11.0.
Reproduction
export function parenWholeAssign(p: number): number {
//@ ensures p === 0 ==> \result === 0
let x = p;
(x = 7);
return x;
}
parenWholeAssign(0) returns 7 in JavaScript. lsc gen --backend=dafny emits:
method parenWholeAssign(p: int) returns (res: int)
ensures ((p == 0) ==> (res == 0))
{
var x := p;
var _ := (x == 7);
return x;
}
and dafny verify reports 1 verified, 0 errors.
The same happens with an assignment in an initializer:
export function assignInInit(p: number): number {
//@ ensures p === 0 ==> \result === 0
let x = p;
const y = (x = 7);
return x;
}
emits var y := (x == 7); and verifies (1 verified, 0 errors), while JavaScript returns 7.
if ((x = 7) > 0) emits if ((x == 7) > 0), which Dafny rejects as a type error, so that form fails loudly.
Expected
A parenthesized assignment statement such as (x = 7); should be lowered the same way as x = 7;. An assignment anywhere else inside an expression should either be supported or be rejected with a source-positioned error. It should never become an equality test.
Likely cause
In tools/src/extract.ts:
extractExprhandlesop === "="by returning{ kind: "binop", op: "=", ... }(around line 516, commented "extract as binop for now"). Later passes treat binop"="as equality, which the Dafny emitter prints as==.desugarStmtExpr(line 1350) checksNode.isBinaryExpression(expr)without unwrapping aParenthesizedExpression, so(x = 7);falls through to an expression statement and reaches the branch above. Theforincrementor path also callsdesugarStmtExpr.
Related
- #355: a parenthesized assignment target,
(x) = 7, in the same function. That one fails to parse in Dafny. Both need parentheses unwrapped indesugarStmtExpr.
- 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
-
Dificultad 3/5 1-2 días Aptitud para principiantes 62/100
midspiral/LemmaScript#354 ·
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
-
enhancement from-app needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
nightly-labs/openbot#14986 ·
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