Skip to content

String literals need escape sequences #185

Open

Description

@Kinflou

String literals have no escape sequences, so some strings can't be written at all:

const Q: string = "say \"hi\""   // doesn't parse: a string can't contain `"`
const N: string = "a\nb"          // builds, as a backslash and an `n`, not a newline

StringLiteral is "([^"]*)", kept as written. Generators already escape what they're given ("a\nb" in a schema becomes "a\\nb" in Rust and TypeScript), so values survive; there's just no way to write a quote, a newline or a non-printing character.

Proposal: the escapes most languages share:

Escape Character
\" "
\\ \
\n, \r, \t newline, carriage return, tab
\0 NUL
\u{1F600} any Unicode scalar value, 1 to 6 hex digits (no surrogates)

Any other backslash sequence is a build error, so a future escape can be added without changing what an existing string means. The same rules hold in f-strings (error messages, validator messages), alongside {{ and }}.

Compatibility: a constant or default written today with \n, \t, \0 or \\ changes value. That's acceptable before 1.0; version comparison reports each changed constant as it does any value change. Other backslashes become errors, pointing at the escape to use.

Found during the bug hunt; requested 2026-11-02.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions