Generic interfaces and object type aliases lose their type parameters in Dafny
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
- 49/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- backend-api-design, tooling
Línea de trabajo
Start with tools/src/extract.ts at extractRecord, then compare its type parameter handling with parseDeclareType; inspect the signature scan around line 2821 and the lemma call generation in tools/src/transform.ts around line 2528. Add fixtures for the Stack/Popped example, generic empty, and the type table in SPEC.md. Done when the interface and alias examples and empty<T>() verify, and generic records are documented as retaining unbounded type parameters.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
This was generated by AI during triage.
Context
DESIGN_LS_IN_LS.md §5.1 and §9 step 3 deferred generic datatype work on 2026-07-21. The note says erasure is uneven ("record decls erase, Dafny union decls stay parametric"), to be picked up "if a case study ever hits it", and that today "no case study hits the broken path".
I hit it in my production code. An undo/redo history module is generic over the snapshot it stores (HistoryState<TSnapshot>, HistoryEntry<TSnapshot>). Its eight helper functions have no extends bound on TSnapshot, so SPEC.md's type table applies its <T> / <T extends U> row: "T kept as type param (bound dropped)". The functions do keep it. The record declarations do not, so the model does not resolve.
Problem
export interface Entry<T> {
value: T;
label: string;
}
export interface Stack<T> {
items: readonly Entry<T>[];
}
export interface Popped<T> {
stack: Stack<T>;
top: Entry<T>;
}
export function push<T>(s: Stack<T>, e: Entry<T>): Stack<T> {
//@ verify
//@ ensures \result.items.length === s.items.length + 1
return { items: [...s.items, e] };
}
export function pop<T>(s: Stack<T>): Popped<T> | null {
//@ verify
//@ ensures (\result === null) === (s.items.length === 0)
if (s.items.length === 0) return null;
return {
stack: { items: s.items.slice(0, s.items.length - 1) },
top: s.items[s.items.length - 1],
};
}
lsc gen --backend=dafny emits:
type Popped(==)
datatype Stack = Stack(items: seq<Entry<T>>)
datatype Entry = Entry(value: T, label_: string)
function push<T>(s: Stack<T>, e: Entry<T>): Stack<T>
{
Stack((s.items + [e]))
}
function pop<T>(s: Stack<T>): Option<Popped<T>>
{
if (|s.items| == 0) then
None
else
Some((Stack(s.items[0..(|s.items| - 1)]), s.items[(|s.items| - 1)]))
}
Dafny reports 11 resolution errors: Wrong number of type arguments (1 instead of 0) for each use of Stack, Entry and Popped, and Type or type parameter is not declared in this scope: T inside the two datatypes.
There are three separate problems here:
- The record declarations drop
<T>.extractRecordintools/src/extract.ts(around line 1168) returns{ name, kind: "record", fields }without type parameters, while the field types still sayEntry<T>. The same source written astype Stack<T> = { … }aliases fails the same way (14 errors). - A generic type used only in a return type becomes opaque.
Popped<T>appears only inPopped<T> | null, and it is emitted astype Popped(==), with the result built as a tuple. The signature scan around line 2821 marks a type as needed only when its base name matches^[A-Za-z_]\w*(?:\.\w+)*$, whichPopped<T>does not. A zero-argument function makes this worse:function empty<T>(): Stack<T> { return { items: [] }; }emitstype Stack(==)and the body([]). - A zero-argument generic function cannot be called from its own lemma. Once the datatypes are generic,
ensures (|empty().items| == 0)fails withtype parameter 'T' (inferred to be '?') in the function call to 'empty' could not be determined. The lemma call built intools/src/transform.ts(around line 2528) has no type arguments. Writingempty<T>()verifies.
For comparison, the same records written as //@ declare-type Entry<T> { value: T, label: string } and //@ declare-type Stack<T> { items: Entry<T>[] } emit datatype Entry<T> and datatype Stack<T>, and push verifies (1 verified, 0 errors). That form is our current workaround, but it needs the type written twice.
Checked on main at 6b18f23 (0.6.8) with Dafny 4.11.0. I did not check the Lean backend.
Proposal
Keep the deferred parametricity design out of scope. Make the record path match what declare-type and discriminated unions already do:
extractRecordrecords the declaration's type parameters, asparseDeclareTypedoes.- The signature scan marks the base name of a generic reference such as
Popped<T>, so the record is emitted. - The lemma's call to a pure generic function passes the function's type parameters as explicit type arguments, for example
empty<T>().
Non-generic records keep byte-identical output. Instantiated generics such as Stack<number> stay out of scope, as §5.1 describes.
We have run equivalent changes as a local patch against 0.6.6 in a downstream project, where the history module now verifies (24 Dafny tasks). I can port them to tools/src as a PR with fixtures.
Acceptance criteria
- The
Stack/Poppedexample above verifies, written withinterfaceand withtypealiases. empty<T>()withensures \result.items.length === 0verifies.- SPEC.md's type table says that generic records keep unbounded type parameters.
- 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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de midspiral/LemmaScript
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
midspiral/LemmaScript#308 ·
Los mantenedores suelen responder en 1 día
-
Dafny: `toUpperCase`/`toLowerCase` are modeled as ASCII-only, so false contracts about non-ASCII text verifyPosiblemente ocupada @quangng2000 la tomó hace 1 día. Abierto
midspiral/LemmaScript#312 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 1-2 días Aptitud para principiantes 56/100
midspiral/LemmaScript#311 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 48/100
midspiral/LemmaScript#310 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 67/100
midspiral/LemmaScript#309 ·
Los mantenedores suelen responder en 1 día
Todos los issues de midspiral/LemmaScript
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
vercel-labs/ui#809 ·
Los mantenedores suelen responder en 1 día
-
bot:ai-assisted component:platform-js status:untriaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
midnightntwrk/platform-js#38 ·
-
[bug] Second false positive on high-cost plugin alert: detection only compares patch entry id, community plugin dsh-auto | [bug] 高成本插件告警第二次误报:检测只比对 patch 条目 id,社区插件 dsh-auto-review 被认成 @deepseek-ai/dsh-experimental-auto-reviewPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ranxianglei/billion-context#7068 ·
Los mantenedores suelen responder en 1 día
-
vendor: bump whisper.cpp past 6a8addd — the current pin aborts the app on a failed Metal initAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
mybigday/whisper.rn#348 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
six-group/six-webcomponents#600 ·