Skip to content

Prefer the first lexical error in a string literal segment #1553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/SwiftParser/Lexer/Cursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,10 @@ extension Lexer.Cursor {
return Lexer.Result(.stringSegment, error: error)
}
case .error(let errorKind):
error = LexingDiagnostic(errorKind, position: self)
// Only overwrite error if we had not found an earlier error yet
if error == nil {
error = LexingDiagnostic(errorKind, position: self)
}
self = clone
case .endOfString:
return Lexer.Result(
Expand Down
7 changes: 7 additions & 0 deletions Tests/SwiftParserTest/ExpressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ final class ExpressionTests: XCTestCase {
DiagnosticSpec(locationMarker: "2️⃣", message: #"expected '"' to end string literal"#, fixIts: [#"insert '"'"#]),
]
)

assertParse(
###""1️⃣\1 \1""###,
diagnostics: [
DiagnosticSpec(message: "invalid escape sequence in literal")
]
)
}

func testAdjacentRawStringLiterals() {
Expand Down