Reject adjacent string literals#5340
Merged
Merged
Conversation
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
637dc32 to
8171309
Compare
jemc
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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