typeof unsupported in spec expressions and emitted verbatim in bodies

Open
#266 0 comments 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
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Start by locating the annotation parser and body lowering or code generation paths that handle expressions; the issue does not name specific files or tests. Reproduce the supplied example and inspect how typeof is parsed in the ensures expression and emitted in the function body. Done means both paths handle the construct correctly, or the unsupported case produces a diagnostic naming typeof.

Written by the indexing model from the issue text.

Description

Summary

typeof is rejected in spec expressions at parse time and emitted verbatim (unresolved) in bodies, so runtime type guards — the idiom every JS codebase uses for input validation — are unmodellable:

//@ backend dafny
export function isNonNeg(v: unknown): boolean {
//@ verify
//@ ensures \result === (typeof v === "number" && v >= 0)
  return typeof v === "number" && v >= 0;
}

Evidence

  • Before (spec): ERROR: Expected punc ')', got {"type":"ident","value":"v"} — the annotation grammar has no typeof production. Exit 1.
  • Before (body only, trivially-true ensures): generation succeeds but Dafny reports unresolved identifier: typeof — the operator passes through unlowered. Exit 1.
  • After (expected): either typeof narrowing per the documented union-discrimination rule, or a diagnostic that names the construct instead of a punctuation error.

Merge Danger

Door: two-way — both paths fail loud, nothing half-proved.

Blast radius: toolchain — any unknown-typed input validation (the standard JS boundary idiom) cannot be annotated today.

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.