Skip to content

Commit

Permalink
Merge pull request swiftlang#637 from omochi/fix-nested-interpolation…
Browse files Browse the repository at this point in the history
…-crash

Fix crash on nested interpolation
  • Loading branch information
CodaFi authored Aug 26, 2022
2 parents 40518fa + 25703b1 commit 6eb1701
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ extension Lexer.Cursor {
}
if !self.isAtEndOfFile, self.peek() == UInt8(ascii: "\\") &&
TmpPtr.delimiterMatches(customDelimiterLength) &&
TmpPtr.advance() == UInt8(ascii: "(") {
TmpPtr.peek() == UInt8(ascii: "(") {
// Consume tokens until we hit the corresponding ')'.
self = Self.skipToEndOfInterpolatedExpression(TmpPtr, IsMultilineString)
if self.advance(if: { $0 == Unicode.Scalar(")") }) {
Expand Down
18 changes: 18 additions & 0 deletions Tests/SwiftParserTest/Expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,24 @@ final class ExpressionTests: XCTestCase {
return "Fixit: \(range.debugDescription) Text: \"\(text)\""
"""#
}

try AssertParse({ $0.parseExpression() }) {
#"""
"text \(array.map({ "\($0)" }).joined(separator: ",")) text"
"""#
}

try AssertParse({ $0.parseExpression() }) {
#"""
"""
\(gen(xx) { (x) in
return """
case
"""
})
"""
"""#
}
}

func testStringLiterals() throws {
Expand Down

0 comments on commit 6eb1701

Please sign in to comment.