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

Open
#276 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

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.

Written by the indexing model from the issue text.

Description

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.
Dominant language
TypeScript
Stars
113
Forks
13
Avg merge
15h 35m
Merged PRs (30d)
56

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from midspiral/LemmaScript

All issues in midspiral/LemmaScript

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.