Skip to content

Commit 6143e9d

Browse files
committed
Remove assertion that the closing quote of a string literal must not have leading trivia
1 parent 7db61b4 commit 6143e9d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Sources/SwiftParser/StringLiterals.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ extension Parser {
309309
// -------------------------------------------------------------------------
310310
// Precondition
311311

312-
assert(closeQuote.leadingTriviaByteLength == 0, "Closing quote produced by the lexer should not have leading trivia because we would drop it during post-processing")
313312
assert(
314313
allSegments.allSatisfy {
315314
if case .stringSegment(let segment) = $0 {
@@ -349,7 +348,7 @@ extension Parser {
349348
middleSegments: &middleSegments
350349
)
351350

352-
if !closeDelimiterOnNewLine {
351+
if !closeDelimiterOnNewLine || closeQuote.leadingTriviaByteLength != 0 {
353352
unexpectedBeforeCloseQuote = [closeQuote]
354353
closeQuote = RawTokenSyntax(missing: closeQuote.tokenKind, leadingTriviaPieces: [.newlines(1)], arena: self.arena)
355354

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,4 +1652,18 @@ final class StatementExpressionTests: XCTestCase {
16521652
diagnostics: [DiagnosticSpec(message: "unexpected code '@case' in 'switch' statement")]
16531653
)
16541654
}
1655+
1656+
func testUnterminatedInterpolationAtEndOfMultilineStringLiteral() {
1657+
AssertParse(
1658+
#"""
1659+
"""\({(1️⃣})
1660+
2️⃣"""3️⃣
1661+
"""#,
1662+
diagnostics: [
1663+
DiagnosticSpec(locationMarker: "1️⃣", message: "expected value and ')' to end tuple"),
1664+
DiagnosticSpec(locationMarker: "2️⃣", message: #"unexpected code '"""' in string literal"#),
1665+
DiagnosticSpec(locationMarker: "3️⃣", message: #"expected '"""' to end string literal"#),
1666+
]
1667+
)
1668+
}
16551669
}

0 commit comments

Comments
 (0)