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

Đang mở Phù hợp với người mới
#355 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
compilers

Hướng nghiên cứu

Lỗi nằm ở desugarStmtExpr trong tools/src/extract.ts, hàm này lấy vế đích của phép gán từ getText() mà không bóc ParenthesizedExpression; kiểm tra havoc() trong extractStmts cũng dùng Node.isIdentifier trên toán hạng bên trái. Bắt đầu bằng cách tái hiện ví dụ (x) = 7 với lsc gen --backend=dafny. Hoàn thành khi vế đích có ngoặc phát ra x := 7;, giống đầu ra của dạng không có ngoặc, và thao tác ghi được theo dõi bởi lượt havoc.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
TypeScript
Star
113
Fork
13
Merge trung bình
15 giờ 35 phút
Pull request đã merge (30 ngày)
56

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của midspiral/LemmaScript

Tất cả issue của midspiral/LemmaScript

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.