An inline object type on a parameter or local is emitted as TypeScript text

Aperta
#276 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start by reading the lowering paths that emit types and object literals for the Dafny and Lean backends, then find the tests covering synthetic names for interface fields and return types. Add regression coverage for the sumA parameter and mk local annotation; the issue is done when both examples either resolve on both backends or produce an lsc error naming the inline type.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

SPEC.md says anonymous object types in interface fields and in function return types get synthetic datatype names (SpecEntryDecision, ParseSpecYamlResult). The same type written on a parameter or a local variable gets no name. Both backends emit the TypeScript spelling as a type name, and the generated files do not parse.

Reproduced on upstream main at 36eb31d (LemmaScript 0.6.8).

Reproduction

export function sumA(p: { x: number; y: number }): number {
  return p.x + p.y;
}

export function mk(n: number): number {
  const r: { k: number } = { k: n };
  return r.k;
}

lsc gen --backend=dafny emits:

type { x: number; y: number }(==)

function sumA(p: { x: number; y: number }): int
{
  (p.x + p.y)
}

function mk(n: int): int
{
  var r := (n);
  r.k
}

dafny resolve stops at the first line with invalid Ident. mk also lowers the record literal to (n), which has no field k.

lsc gen --backend=lean emits opaque { x: number; y: number } : Type and def sumA (p : { x: number; y: number }) : Int, and lowers the literal to let r := { k := n }.

A named alias, type Pt = { x: number; y: number }, works in the parameter position.

Expected

Either the parameter and local positions get synthetic names, as interface fields and return types do (for example SumAP and MkR), or lsc rejects an inline object type in those positions with a message that suggests a named alias. Both backends fail loudly today, so no false proof results; the cost is valid TypeScript that does not compile and an error message that points at generated text.

Acceptance criteria

  • sumA and mk above either generate code that resolves on both backends or are rejected by lsc with an error naming the inline type.
  • A regression test covers an inline object type on a parameter and on a local annotation.
Lingua principale
TypeScript
Stelle
113
Fork
13
Merge medio
15h 35m
PR unite (30g)
56

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di midspiral/LemmaScript

Tutte le issue di midspiral/LemmaScript

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.