Assigning a defined value to an optional does not narrow it for later reads
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- compilers
Direzione di ricerca
Start with the narrowing rules documented in TOOLS.md to see how flow-sensitive narrowing is currently expressed, then find the lowering code that emits Some(5) for the assignment and the read that emits return o;. The gap is that assignment-based narrowing is not tracked at the read, so the read lowers to the Option value instead of the unwrapped one. Work through all three forms in the reproduction (plain assignment, the === undefined guard, and ??) and add a regression test per form so dafny verify passes on each.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
TypeScript narrows an optional variable after it is assigned a defined value. Three common forms:
let o = p;
o = 5;
return o; // TypeScript: o is number here
let o = p;
if (o === undefined) { o = 5; }
return o; // TypeScript: o is number here
let o = p;
o = o ?? 5;
return o; // TypeScript: o is number here
TypeScript narrows o to number after the assignment, because every path leaves it defined. lsc emits the assignments correctly (o := Some(5) in the first two), but then returns o as an Option. Dafny rejects the output, so no false proof results. None of the narrowing rules in TOOLS.md covers narrowing by assignment.
Reproduced on upstream main at add6ccd (0.6.10).
Reproduction
export function assignOutside(p?: number): number {
let o = p;
if (o === undefined) { o = 5; }
return o;
}
emits:
method assignOutside(p: Option<int>) returns (res: int)
{
var o := p;
if (match o { case Some(i_) => false case None => true }) {
o := Some(5);
}
return o;
}
dafny verify reports Method return value mismatch (expected int, got Option<int>).
The other two forms fail the same way: let o = p; o = 5; return o; and let o = p; o = o ?? 5; return o; report the same error. const o = p ?? 5; return o; verifies, because the new variable is declared with the non-optional type.
Expected
After an assignment that leaves x defined on every path, such as x = 5, if (x === undefined) { x = 5; } or x = x ?? 5, a read of x where TypeScript's type is the inner type lowers to the unwrapped value. In the reproduction, replacing return o; with return o.value; by hand verifies, because Dafny knows o.Some? on both paths.
If this stays unsupported, lsc should report it at the read rather than emit Dafny that does not type-check.
Acceptance criteria
- All three forms above generate Dafny that verifies.
- A regression test covers each form with a read after the assignment.
- 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 `const` or `let` inside a bare `{ }` block stays in scope after the block, so a false `ensures` can verifyForse già presa @namin l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 15/100
midspiral/LemmaScript#361 ·
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
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