Indexed access type annotations (T["k"]) are emitted as Dafny type names
This was generated by AI during triage.
Problem
An annotation such as x: Info["kind"] reaches parseTsType as source text. That parser has no type checker, so it keeps the text as an opaque type name, and the Dafny output declares type Info["kind"](==), which does not parse.
Reproduced on upstream main at 36eb31d (LemmaScript 0.6.8).
Reproduction
export interface Info { kind: "a" | "b"; count: number }
export function sameKind(x: Info["kind"], y: Info["kind"]): boolean {
return x === y;
}
npx tsx tools/src/lsc.ts gen --backend=dafny repro.ts emits:
type Info["kind"](==)
datatype Info = Info(kind: string, count: int)
function sameKind(x: Info["kind"], y: Info["kind"]): bool
{
(x == y)
}
dafny resolve reports this symbol not expected in Dafny (a parse error).
Return types and rest parameters produce the same declarations, for example function kindOf(i: Info): Info["kind"] and method total(counts: seq<Info["count"]>), and the nested form Info["tags"][number] | undefined emits type Info["tags"][number](==) and Option<Info["tags"][number]>.
Proposed fix
When an annotation contains an indexed access type, use the checker's resolved type for that annotation instead of its source text. Annotations without one are unchanged.
Acceptance criteria
- The reproduction emits
function sameKind(x: string, y: string): booland resolves. - A regression test covers parameter, return, rest-parameter, local,
for-initializer and lambda annotations, includingT["k"][number], and verifies the generated module.