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

Abierto
#258 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
113
Forks
13
Merge medio
16 h 22 min
PR fusionados (30 d)
40

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de midspiral/LemmaScript

Todos los issues de midspiral/LemmaScript

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.