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

オープン
#6,396 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
compilers

調査の方向性

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.

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

説明

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.

主要言語
Rust
スター
10.9k
フォーク
261
平均マージ
3日 20時間
マージ済み PR(30日)
85

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

PRQL/prql のほかの issue

PRQL/prql の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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