Skip to content

A comptime string value re-emitted as a literal carries the raw marker (#1246) - #1255

Merged
ehartford merged 1 commit into
mainfrom
comptime-str-reemit-raw
Sep 21, 2026
Merged

ehartford merged 1 commit into
mainfrom
comptime-str-reemit-raw

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1246.

const C: str = r#"a\"b\n"# printed a"b and a newline. const desugars to a comptime-wrapped let; the evaluator decodes the literal once (comptime_decode_string_escapes honors the parser's \x01raw\x01 marker and returns the bytes as written), then ComptimeTransform re-emitted the CV_STR value as a fresh NK_STRING_LIT interned without the marker, so codegen's decoder processed the already-decoded \" and \n a second time. Same at ct_build_string_lit (derived display/variant-name literals).

Both re-emission sites go through ct_raw_literal_text: a literal the transform emits holds decoded bytes and says so. Found when switching the embedded stdlib generators to const broke every use std.build program (#1247). behav_const_raw_string_keeps_escapes pins const/let/plain-const byte for byte.

Battery (seed-driven, worktree): build, :fixpoint, :test, :test-green, :last-green all rc=0.

#1246)

`const C: str = r#"a\"b\n"#` printed `a"b` and a newline. `const` desugars
to a comptime-wrapped let; the evaluator decodes the literal once
(comptime_decode_string_escapes honors the parser's `\x01raw\x01` marker
and returns the bytes as written), then ComptimeTransform re-emitted the
CV_STR value as a fresh NK_STRING_LIT interned WITHOUT the marker, so
codegen's decoder processed the already-decoded `\"` and `\n` a second
time. Same at ct_build_string_lit (derived display/variant-name literals).

Both re-emission sites now go through ct_raw_literal_text: a literal the
transform emits holds decoded bytes and says so. Found when switching the
embedded stdlib generators to `const` broke every `use std.build` program
(#1247); behav_const_raw_string_keeps_escapes pins const/let/plain-const
byte for byte.
@ehartford
ehartford merged commit c21f8c2 into main Sep 21, 2026
4 of 5 checks passed
@ehartford
ehartford deleted the comptime-str-reemit-raw branch September 21, 2026 17:42
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.

comptime re-interprets escapes in a raw string literal: const C: str = r#"a\\"b"# yields a"b

1 participant