Skip to content

Commit 7650238

Browse files
authored
Merge pull request #1553 from cbjeukendrup/prefer_first_lex_err_in_string_literal
Prefer the first lexical error in a string literal segment
2 parents 6bb19ef + f7c66ea commit 7650238

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,10 @@ extension Lexer.Cursor {
19131913
return Lexer.Result(.stringSegment, error: error)
19141914
}
19151915
case .error(let errorKind):
1916-
error = LexingDiagnostic(errorKind, position: self)
1916+
// Only overwrite error if we had not found an earlier error yet
1917+
if error == nil {
1918+
error = LexingDiagnostic(errorKind, position: self)
1919+
}
19171920
self = clone
19181921
case .endOfString:
19191922
return Lexer.Result(

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,13 @@ final class ExpressionTests: XCTestCase {
611611
DiagnosticSpec(locationMarker: "2️⃣", message: #"expected '"' to end string literal"#, fixIts: [#"insert '"'"#]),
612612
]
613613
)
614+
615+
assertParse(
616+
###""1️⃣\1 \1""###,
617+
diagnostics: [
618+
DiagnosticSpec(message: "invalid escape sequence in literal")
619+
]
620+
)
614621
}
615622

616623
func testAdjacentRawStringLiterals() {

0 commit comments

Comments
 (0)