Skip to content

Reject adjacent string literals#5340

Merged
SeanTAllen merged 1 commit into
mainfrom
fix-adjacent-string-literals
May 27, 2026
Merged

Reject adjacent string literals#5340
SeanTAllen merged 1 commit into
mainfrom
fix-adjacent-string-literals

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

@SeanTAllen SeanTAllen commented May 16, 2026

The parser silently accepted two adjacent string literals across a multi-line string boundary as two separate expressions inside the same construct. A typo involving """ would produce a program that compiled but behaved nothing like what was written. The compiler now reports a missing-semicolon error in that case.

Closes #3836

@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label May 16, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label May 16, 2026
The parser's TK_NEWLINE check compared the start lines of the previous
and current tokens to decide whether a real newline separated them.
For multi-line string literals this is wrong: the token's start line
is the line of the opening quote, but the next token can sit on the
same physical line as the string's closing quote. As a result,
adjacent string literals across multi-line strings slipped past the
missing-semicolon check and silently parsed as two expressions inside
the same construct.

Track on each token whether a real newline character preceded it, and
consult that flag from the parser instead of comparing line numbers.
The lexer maintains this as a separate flag from the existing
`lexer->newline` that drives LPAREN_NEW etc., because block comments
intentionally suppress the latter while needing to preserve the
former.

Closes #3836
@SeanTAllen SeanTAllen force-pushed the fix-adjacent-string-literals branch from 637dc32 to 8171309 Compare May 22, 2026 18:36
@SeanTAllen SeanTAllen merged commit 6ad7ef4 into main May 27, 2026
19 checks passed
@SeanTAllen SeanTAllen deleted the fix-adjacent-string-literals branch May 27, 2026 19:25
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label May 27, 2026
github-actions Bot pushed a commit that referenced this pull request May 27, 2026
github-actions Bot pushed a commit that referenced this pull request May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusion with " and """ in syntax and parsing.

3 participants