String index comparison emits char vs string literal: not comparable

Đang mở
#262 0 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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
compilers, tooling

Hướng nghiên cứu

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.

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

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
113
Fork
13
Merge trung bình
16 giờ 22 phút
Pull request đã merge (30 ngày)
40

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.