String index comparison emits char vs string literal: not comparable

Aperta
#262 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
compilers, tooling

Direzione di ricerca

Start by locating the Dafny backend code that lowers string indexing and emits string literals; the issue does not name those files. Reproduce with the included firstIsA example using lsc check --backend=dafny and inspect the generated Dafny and resolver error. Done when the indexed character comparison resolves successfully and the example verifies.

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

Descrizione

Summary

String element access lowers to a Dafny char, but a compared string literal stays a string, so any indexed character comparison fails resolution:

//@ backend dafny
export function firstIsA(s: string): boolean {
//@ verify
//@ ensures \result === (s.length > 0 && s[0] === "a")
  return s.length > 0 && s[0] === "a";
}

Evidence

  • Before: lsc check --backend=dafny generates, then Dafny reports a.verify.dfy(9,46): Error: arguments must have comparable types (got char and string) for (s[0] == "a"). Exit 1, no workaround that keeps indexing (slice comparisons are the only way through).
  • After (expected): the literal is emitted as a Dafny char ('a') or the index access is modeled as a single-character string. Related: #192 (string literal emission in switch cases).

Merge Danger

Door: two-way — generation succeeds, failure surfaces at Dafny resolution, never as a silent wrong proof.

Blast radius: toolchain — any s[i] === "..." comparison in an annotated function.

Lingua principale
TypeScript
Stelle
113
Fork
13
Merge medio
16h 22m
PR unite (30g)
40

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.