nullish reached transform crash on ?? chain over optional record fields

Aperta
#258 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
compilers, tooling

Direzione di ricerca

Start by running lsc check --backend=dafny repro.verify.ts with the 15-line reproduction in the issue; the failure occurs during generation before Dafny runs. Trace how the inline optional record type and chained ?? expression pass through narrowing and the transform. Done when this reproduction generates and verifies cleanly, while the named-interface version still works.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

lsc check --backend=dafny crashes during generation on a chained ?? over optional record fields when the parameter uses an inline object type. The identical body with a named interface verifies clean.

 export function f(
-  entry: { x: number; y?: number } | undefined,   // crash: nullish reached transform
+  entry: Entry | undefined,                       // verifies clean
   context: Ctx
 ): number {
   if (entry !== undefined) {
     const w = context.a ?? entry.y ?? context.b ?? 0;
     return w;
   }
   return -1;
 }

Evidence

  • Before: ERROR: nullish reached transform — narrow should have rewritten it: {"kind":"nullish","left":{"kind":"someMatch",...,"field":"a",...}} (exit 1, pre-Dafny; full log in first comment if needed)
  • After: named interface generates and verifies with an empty lemma body — Dafny program verifier finished with 1 verified, 0 errors

Minimal repro (15 lines, repro.verify.ts):

//@ backend dafny
interface Ctx {
  a?: number;
  b?: number;
}
export function f(
  entry: { x: number; y?: number } | undefined,
  context: Ctx
): number {
//@ verify
  if (entry !== undefined) {
    const w = context.a ?? entry.y ?? context.b ?? 0;
    return w;
  }
  return -1;
}

Run: lsc check --backend=dafny repro.verify.ts (lsc 0.6.6; Dafny/Z3 irrelevant, crash is pre-Dafny).

Merge Danger

Door: two-way

Workaround exists (extract a named interface; zero behavior change), and the crash is generation-only — no faulty proofs escape, the run fails loud.

Blast radius: toolchain

Any file combining inline optional object types with ?? chains is unverifiable until fixed. Related gap (same session, separate report on request): const initializers do not narrow (const fresh = entry !== undefined && ... leaves entry un-narrowed on the right side; SPEC §3.9 lists if/?:/bare-statement only).

Lingua principale
TypeScript
Stelle
113
Fork
13
Merge medio
16h 22m
PR unite (30g)
40

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di midspiral/LemmaScript

Tutte le issue di midspiral/LemmaScript

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.