Skip to content

Commit 6eb1701

Browse files
authored
Merge pull request swiftlang#637 from omochi/fix-nested-interpolation-crash
Fix crash on nested interpolation
2 parents 40518fa + 25703b1 commit 6eb1701

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Sources/SwiftParser/Lexer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ extension Lexer.Cursor {
10291029
}
10301030
if !self.isAtEndOfFile, self.peek() == UInt8(ascii: "\\") &&
10311031
TmpPtr.delimiterMatches(customDelimiterLength) &&
1032-
TmpPtr.advance() == UInt8(ascii: "(") {
1032+
TmpPtr.peek() == UInt8(ascii: "(") {
10331033
// Consume tokens until we hit the corresponding ')'.
10341034
self = Self.skipToEndOfInterpolatedExpression(TmpPtr, IsMultilineString)
10351035
if self.advance(if: { $0 == Unicode.Scalar(")") }) {

Tests/SwiftParserTest/Expressions.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@ final class ExpressionTests: XCTestCase {
194194
return "Fixit: \(range.debugDescription) Text: \"\(text)\""
195195
"""#
196196
}
197+
198+
try AssertParse({ $0.parseExpression() }) {
199+
#"""
200+
"text \(array.map({ "\($0)" }).joined(separator: ",")) text"
201+
"""#
202+
}
203+
204+
try AssertParse({ $0.parseExpression() }) {
205+
#"""
206+
"""
207+
\(gen(xx) { (x) in
208+
return """
209+
case
210+
"""
211+
})
212+
"""
213+
"""#
214+
}
197215
}
198216

199217
func testStringLiterals() throws {

0 commit comments

Comments
 (0)