A `const` or `let` inside a bare `{ }` block stays in scope after the block, so a false `ensures` can verify
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 15/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- typescript
- Ambito
- compilers
Direzione di ricerca
Start in extract.ts, at the Block case of extractStmts, which splices a bare block's statements into the parent. Read forCounterRename/renameRawStmts and renameRawStmt for the existing renaming machinery, and renameSpec for its regex. Done means the repro in the issue no longer verifies the false ensures, and return p after the block refers to the parameter. Linked PR #364 already targets this, so coordinate with it first.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
Extract flattens a bare { ... } block into its parent statement list without renaming its declarations. A const or let inside the block then shadows the outer variable for the rest of the parent block, while in JavaScript it goes out of scope at the closing brace. A false ensures can verify.
Reproduction
//@ backend dafny
//@ ensures \result === 5
export function bareBlock(p: number): number {
{
const p = 5;
}
return p;
}
tsc --strict accepts this. In JavaScript, bareBlock(3) returns 3, which breaks the ensures.
Generated Dafny:
function bareBlock(p: int): int
{
var p := 5;
p
}
lsc check --backend=dafny: 1 verified, 0 errors.
The method lowering behaves the same way. It emits var p := 5; r := (r + p); return p;, and the false ensures verifies.
Two sibling bare blocks that each declare the same name also end up in one Dafny scope.
With a narrowed optional, the shape verifies correctly on main, but only by accident. With #358 applied, it becomes a false proof:
//@ backend dafny
//@ ensures p !== undefined ==> \result === 1
export function bare(p: number | undefined): number {
if (p !== undefined) {
{
const p = 1;
}
return p;
}
return 1;
}
- In JavaScript,
bare(7)returns7. - On
main, the output readsi_p_valafter the flattenedvar p := 1;, which happens to match JavaScript, and Dafny refutes the claim. - With #358, substitution stops at the flattened
let, which matches the emitted Dafny scope. The output isvar p := 1; p, and it verifies:1 verified, 0 errors.
Checked on main at 2ccd0a5 (0.6.11) with Dafny 4.11.0.
Expected
After the closing brace, reads of p refer to the outer p. Here that means return p returns the parameter.
Likely cause
The Block case in extractStmts (extract.ts, result.push(...extractStmts(s.getStatements()))) splices the block's statements into the parent.
Lowering the block to if (true) { ... } does not fix it, because the pure-body lowering leaks branch-local declarations too (#362).
A likely fix is to alpha-rename each top-level let, const or ghostLet in a bare block that collides with a name visible after the block. The rename would apply to the block's statements before splicing, using the same machinery as forCounterRename/renameRawStmts. That needs three more changes:
- register the new names in
_userNamesso later fresh names avoid them - add a
ghostLetcase torenameRawStmt - make the
renameSpecregex skip field accesses such ass.p
Related
- #351 (shadowing in narrowing substitution).
- #358 fixes #351, and with it the narrowed repro above changes from a refuted claim to a false proof.
- #360 (closure before a same-name declaration) and #362 (
if-branch scoping).
- Lingua principale
- TypeScript
- Stelle
- 113
- Fork
- 13
- Merge medio
- 15h 35m
- PR unite (30g)
- 56
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
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 midspiral/LemmaScript
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
midspiral/LemmaScript#355 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
In a pure function body, a `const` declared inside an `if` branch stays in scope after the `if`, so a false `ensures` can verifyForse già presa @namin l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
midspiral/LemmaScript#362 ·
I maintainer di solito rispondono entro 1 giorno
-
A closure declared before a same-name `const` or `let` in its block reads the outer variable, so a false `ensures` can verifyForse già presa @namin l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
midspiral/LemmaScript#360 ·
I maintainer di solito rispondono entro 1 giorno
-
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 verifyForse già presa @namin l’ha presa oggi. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 30/100
midspiral/LemmaScript#356 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
midspiral/LemmaScript#354 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di midspiral/LemmaScript
Issue simili
-
bug done
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
neavo/LinguaGacha#1124 ·
I maintainer di solito rispondono entro 1 giorno
-
[fullsend] E2E: backstage-microsoft-auth — catalogQuery missing error handler for network errorsForse già presa @fullsend-ai-coder l’ha presa oggi. Apertae2e-failure ready-to-code
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 78/100
redhat-developer/rhdh-plugin-export-overlays#4821 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
brylie/mission-island#225 ·
I maintainer di solito rispondono entro 1 giorno
-
status/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
google-gemini/gemini-cli#30412 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno