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

Open
#258 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
compilers, tooling

Research direction

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.

Written by the indexing model from the issue text.

Description

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).

Dominant language
TypeScript
Stars
113
Forks
13
Avg merge
15h 35m
Merged PRs (30d)
56

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from midspiral/LemmaScript

All issues in midspiral/LemmaScript

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.