Dafny: a `string | readonly string[]` value passed where that same union is expected is wrapped again in `NonArrayBranch`; `.includes()` on the narrowed array fails
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
- 56/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- backend-api-design, compilers
Línea de trabajo
Start in tools/src/resolve.ts at coerceToTargetTy, as the issue identifies that function as the source of the repeated union wrapping. Trace how narrowed array types are represented and how method calls are resolved in both function bodies and spec expressions. Done means passing an already-union-typed value preserves its type and narrowed-array calls such as .includes() work; the payload names no test file, so locate or add coverage for both failures.
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/resolve.ts, coerceToTargetTy (around line 200).
A JWT aud claim is one string or a list. lsc synthesizes ArrayOf_string_Or_string = ArrayBranch(arr: seq<string>) | NonArrayBranch(val: string) for it, and a function that takes the union and narrows it with Array.isArray verifies. Passing a value that already has the union type does not.
//@ backend dafny
export interface Claims { readonly aud: string | readonly string[] }
export function audiences(aud: string | readonly string[]): string[] {
//@ verify
if (Array.isArray(aud)) return [...aud]
return [`${aud}`]
}
export function audienceCount(c: Claims): number {
//@ verify
return audiences(c.aud).length
}
datatype ArrayOf_string_Or_string = ArrayBranch(arr: seq<string>) | NonArrayBranch(val: string)
datatype Claims = Claims(aud: ArrayOf_string_Or_string)
function audienceCount(c: Claims): int
{
|audiences(NonArrayBranch(c.aud))|
}
i5.dfy(19,30): Error: incorrect argument type for datatype constructor parameter 'val' (expected string, found ArrayOf_string_Or_string)
coerceToTargetTy wraps any value whose type is not array in NonArrayBranch when the target is a synth array-union. It doesn't check whether the value already has the target type. The same happens with const a = c.aud (var a := NonArrayBranch(c.aud)). It also happens inside if (Array.isArray(a)) for the narrowed array, which is emitted as audiences(NonArrayBranch(i_a_arr)).
Second gap: .includes() on the narrowed array. Element access and .length work after Array.isArray, but a method call is resolved against the union:
//@ backend dafny
export function has(aud: string | readonly string[], want: string): boolean {
//@ verify
//@ ensures Array.isArray(aud) ==> \result === aud.includes(want)
if (Array.isArray(aud)) { const xs: readonly string[] = aud; return xs.includes(want) }
return aud === want
}
ERROR: Dafny emission failed for 'has' in i5b.ts: Unsupported Dafny method call: .includes() on user
The body above is fine, because it copies into a typed local first. The ensures fails, and if (Array.isArray(aud)) return aud.includes(want) fails the same way in a body. typeof aud === "string" is not an alternative (see #266).
In TypeScript, all of this typechecks and narrows as expected.
Suggested fix:
- In
coerceToTargetTy, returnvalueunchanged whenvalue.tyis already the synth union (value.ty.kind === "user" && value.ty.name === targetTy.name). Use the narrowed binder's type (seq<T>/U) when the value is a narrowed path. - Give the narrowed binder its array type when lowering method calls, so
.includes,.someand the others resolve, in spec expressions too.
Workaround: keep the union out of verified signatures. Normalise aud to readonly string[] in unverified code, and verify functions over the array. The local-copy trick above covers .includes() in bodies, but not in contracts.
- 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 ·