Skip to content

Parser: nodes in an f-string hole map back through the stripped escape layer, so their spans are the file's (#2270) - #2663

Merged
ehartford merged 1 commit into
fix-2316from
fix-2270
Oct 25, 2026
Merged

ehartford merged 1 commit into
fix-2316from
fix-2270

Conversation

@ehartford

@ehartford ehartford commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Root cause: offset_interpolated_expr_spans (src/Parser.w) added one constant
(the hole's start) to every node reparsed from interp_normalize_expr_text,
which strips one escape layer (\" becomes "). Each stripped backslash
put the nodes after it one byte early: in
print(f"{count_all([\"a\", \"b\", undefined_name_2270])}") the error
pointed at column 35; the name starts at 39.

The normalizer returns its text with a per-byte map to the hole offset each
output byte came from (InterpNormalized { text, src }); a node's start maps
through it and its end through its last byte.

Test: test/compile_errors/err_2270_fstring_hole_escaped_quote_span.w
(expect-check-fail at :9:39; the installed compiler says :9:35).

Closes #2270

…e layer, so their spans are the file's (#2270)

Root cause: offset_interpolated_expr_spans (src/Parser.w) added one constant
(the hole's start) to every node reparsed from interp_normalize_expr_text,
which strips one escape layer (`\"` becomes `"`). Each stripped backslash
put the nodes after it one byte early: in
`print(f"{count_all([\"a\", \"b\", undefined_name_2270])}")` the error
pointed at column 35; the name starts at 39.

The normalizer returns its text with a per-byte map to the hole offset each
output byte came from (InterpNormalized { text, src }); a node's start maps
through it and its end through its last byte.

Test: test/compile_errors/err_2270_fstring_hole_escaped_quote_span.w
(expect-check-fail at :9:39; the installed compiler says :9:35).
@ehartford
ehartford added this pull request to stack #2668 October 25, 2026 22:01
@ehartford ehartford changed the title fix 2270 Parser: nodes in an f-string hole map back through the stripped escape layer, so their spans are the file's (#2270) Oct 25, 2026
@ehartford
ehartford marked this pull request as ready for review October 25, 2026 22:13
@ehartford
ehartford merged commit 1b20447 into main Oct 25, 2026
@ehartford
ehartford deleted the fix-2270 branch October 25, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nodes inside an f-string hole with escaped quotes carry wrong spans

1 participant