Dafny: `<T extends B>` is replaced by `B`, so a call with any other record type is ill-typed (and an inline `B` is emitted as TypeScript text)
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
- 48/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
Línea de trabajo
Start in tools/src/extract.ts, in extractFunctionInner around line 2122, and trace how bounded type parameters are added to _typeParamMap; compare the inline object bound path with the synthetic naming described in issue #276. Reproduce both examples with Dafny 4.11 and inspect the generated Dafny and its type errors. Done means wider record arguments retain the generic return type, inline bounds no longer emit TypeScript syntax, or unsupported cases receive a clear diagnostic.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Version: lsc 0.6.10 (npm), Dafny 4.11. Still present on main at 93283ec, tools/src/extract.ts, extractFunctionInner (around line 2122).
When a bound is a record, extractFunctionInner substitutes T with the bound's text (_typeParamMap.set(tp.getName(), constraint.getText())). This lets field reads through T typecheck. But it loses the reason for writing a bounded generic, which is that callers pass a type wider than the bound. It breaks in two ways.
1. A caller with a wider record doesn't resolve.
//@ backend dafny
export interface HasParams { readonly params: readonly string[] }
export interface Fn { readonly name: string; readonly params: readonly string[] }
export function firstOrSelf<T extends HasParams>(fn: T): T {
//@ verify
return fn
}
export function paramCount<T extends HasParams>(fn: T): number {
//@ verify
return fn.params.length
}
export function useIt(f: Fn): number {
//@ verify
//@ ensures \result === f.params.length
return paramCount(f)
}
datatype HasParams = HasParams(params: seq<string>)
datatype Fn = Fn(name: string, params: seq<string>)
function firstOrSelf(fn: HasParams): HasParams { fn }
function paramCount(fn: HasParams): int { |fn.params| }
function useIt(f: Fn): int { paramCount(f) }
i4b.dfy(19,13): Error: incorrect argument type for function parameter 'fn' (expected HasParams, found Fn)
firstOrSelf also returns HasParams. A caller can't get its Fn back, which a T-returning signature promises.
2. An inline object bound is emitted as TypeScript text.
//@ backend dafny
export function paramCount<T extends { params: string[] }>(fn: T): number {
//@ verify
//@ ensures \result === fn.params.length
return fn.params.length
}
type { params: string[] }(==)
function paramCount(fn: { params: string[] }): int
i4.dfy(3,5): Error: invalid Ident
This is the same mechanism as #276 (an inline object type on a parameter), reached through the bound.
In TypeScript, paramCount(f) with f: Fn is fine. T is inferred as Fn, and firstOrSelf(f) has type Fn.
Suggested direction: keep T as a Dafny type parameter. Model the fields the body reads through the bound as accessor functions passed in, or as a trait. Another option is to monomorphise per call-site type: emit paramCount_Fn(fn: Fn) for each record type paramCount is called with. Either way, substituting the bound only works when every caller passes exactly the bound type, so lsc could at least reject a call whose argument type differs from it, with a clear message instead of a Dafny type error. An inline bound needs the synthetic naming that interface fields get (see #276).
Workaround: drop the generic and pass what the function reads, e.g. paramCount(params: readonly string[]), called as paramCount(f.params).
- Lenguaje dominante
- TypeScript
- Estrellas
- 113
- Forks
- 13
- Merge medio
- 16 h 8 min
- PR fusionados (30 d)
- 42
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
-
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
-
Dafny: string-literal unions like `'==' | '!='` map to the same constructor name and the file is rejectedPosiblemente ocupada @DevChiniwala la tomó hoy. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 67/100
midspiral/LemmaScript#309 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 43/100
midspiral/LemmaScript#307 ·
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 76/100
Los mantenedores suelen responder en 1 día
-
[Bug]: Search input loses focus while typing on the Inventory, Reservations and Locations lists (view_configurations enabled)Posiblemente ocupada @medusa-os-bot la tomó hoy. Abiertostatus: needs triaging type: bug version: 2.0
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
medusajs/medusa#17886 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
marimo-team/marimo#11949 ·
Los mantenedores suelen responder en 1 día
-
bug server-time v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
modelcontextprotocol/servers#5559 ·
Los mantenedores suelen responder en 1 día
-
D1 Time Travel restore help advertises 30 days without a plan qualifierPosiblemente ocupada @akhil9tiet la tomó hoy. Abiertobug package:wrangler product:d1
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
cloudflare/workers-sdk#17000 · 2 comentarios ·
Los mantenedores suelen responder en 1 día