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

オープン 初心者向け
#355 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
compilers

調査の方向性

バグは tools/src/extract.ts の desugarStmtExpr にあります。この関数は、ParenthesizedExpression を展開せずに getText() から代入先を取得しています。また、extractStmts 内の havoc() のチェックも、左辺のオペランドに対して Node.isIdentifier を使っています。まず lsc gen --backend=dafny で (x) = 7 の例を再現してください。括弧付きの代入先が、括弧なしの形と同じ x := 7; を出力し、その書き込みが havoc パスで追跡されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
TypeScript
スター
113
フォーク
13
平均マージ
15時間 35分
マージ済み PR(30日)
56

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

midspiral/LemmaScript のほかの issue

midspiral/LemmaScript の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。