A parenthesized assignment target such as `(x) = 7` is emitted with its parentheses, and Dafny cannot parse it

Aperta Adatta ai principianti
#355 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à
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
compilers

Direzione di ricerca

Il bug si trova in desugarStmtExpr in tools/src/extract.ts, che prende l'obiettivo dell'assegnazione da getText() senza scartare una ParenthesizedExpression; anche il controllo havoc() in extractStmts usa Node.isIdentifier sull'operando sinistro. Inizia riproducendo l'esempio (x) = 7 con lsc gen --backend=dafny. È completato quando l'obiettivo tra parentesi genera x := 7;, lo stesso output della forma senza parentesi, e la scrittura è tracciata dal passaggio havoc.

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

Descrizione

Problem

An assignment whose target is in parentheses, such as (x) = 7, is extracted with the parentheses kept in the target name. lsc emits (x) := 7;, which Dafny cannot parse. Because the target is the string "(x)", the write is also invisible to the passes that track assignments to x.

Reproduced on upstream main at 2ccd0a5 (0.6.11) with Dafny 4.11.0.

Reproduction

export function parenAssign(p: number): number {
  let x = p;
  (x) = 7;
  return x;
}

lsc gen --backend=dafny emits (x) := 7;, and Dafny reports:

(6,6): Error: invalid Suffix
1 parse errors detected

(p) = 7 on a parameter, (x) += 2 and (x)++ fail the same way, and --backend=lean also emits (x) := 7.

Expected

Extract should strip parentheses from assignment and update targets, so (x) = 7 produces the same output as x = 7.

Likely cause

desugarStmtExpr in tools/src/extract.ts takes the target from getText() on the left operand (and on the operand of ++/--) without unwrapping a ParenthesizedExpression. The havoc() assignment check in extractStmts uses Node.isIdentifier(expr.getLeft()) and misses parenthesized targets for the same reason.

Related

  • #356: an assignment in expression position, including the parenthesized statement (x = 7);, is extracted as an equality test, and a false ensures verifies. Both need parentheses unwrapped in desugarStmtExpr.
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.