Error labels inside f-strings and s-strings shift left after escape sequences or triple quotes

Đang mở
#6,396 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 3 ngày

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/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ệ
rust
Lĩnh vực
compilers

Hướng nghiên cứu

Start in prqlc/prqlc-parser/src/parser/expr.rs around the interpolation::parse(string, span + 2) call, then inspect the lexer’s TokenKind::Interpolation data and interpolation parsing. Reproduce the reported f-string and s-string cases with escapes and triple quotes, and trace how decoded content maps to source spans. Done means error labels point to the actual expression column for all listed forms without regressing existing interpolation behavior.

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

Mô tả

bug

Error labels inside an f-string or s-string point at the wrong column when the string has escape sequences or uses triple quotes before the {expr}. Each escape sequence moves the label one column left. Triple quotes move it two columns left.

from t
select {x}
derive {y = f"\t\t\t\t{foo}"}

On main (556b1458) the error points at column 20, which is the first \t. foo actually starts at column 24:

 3 │ derive {y = f"\t\t\t\t{foo}"}
   │                    ─┬─
   │                     ╰─── Unknown name `foo`

The same query written as f"aaaa{foo}" labels column 20, which is correct. f"""aaaa{foo}""" also labels column 20, but there foo starts at column 22. s"…" behaves the same way.

Cause. expr.rs#L223 calls interpolation::parse(string, span + 2). That assumes the string's content starts two characters after the token: one for the f/s prefix and one for the quote. It also assumes each character of string maps to one character of the source. Both assumptions break:

  • TokenKind::Interpolation(char, String) holds the string after the lexer has decoded escapes, so \t (two source characters) becomes a single character.
  • A triple-quoted string has two more opening quotes than the + 2 allows for.

A fix would need the lexer to keep enough information to map positions in the decoded content back to source positions: at least the opening quote count, plus an offset table for escapes or the raw slice. TokenKind::Interpolation is the natural place to carry it. Changing that token is a design choice, so this is filed as an issue rather than a direct PR.

The nightly run 36975211955 found this but was stopped by a usage limit before it could act. The repro above was re-run on main at 556b1458. #6383 changes how malformed escapes are decoded but not the span offset, so it doesn't overlap.

Ngôn ngữ chính
Rust
Star
10.9k
Fork
261
Merge trung bình
3 ngày 20 giờ
Pull request đã merge (30 ngày)
85

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

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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 PRQL/prql

Tất cả issue của PRQL/prql

Issue tương tự

Thêm issue về Rust

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.