From 157a296e922615b167a21357d0c7915980dc658c Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Thu, 27 Apr 2023 17:54:56 -0700 Subject: [PATCH] Fix a precondition failure if a generic parameter clause had an additional closing right angle rdar://108624264 --- Sources/SwiftParser/Declarations.swift | 2 +- Tests/SwiftParserTest/DeclarationTests.swift | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftParser/Declarations.swift b/Sources/SwiftParser/Declarations.swift index 0d736f9e873..9c1e5dceff4 100644 --- a/Sources/SwiftParser/Declarations.swift +++ b/Sources/SwiftParser/Declarations.swift @@ -544,7 +544,7 @@ extension Parser { let rangle: RawTokenSyntax if self.currentToken.starts(with: ">") { - rangle = self.consumeAnyToken(remapping: .rightAngle) + rangle = self.consumePrefix(">", as: .rightAngle) } else { rangle = RawTokenSyntax(missing: .rightAngle, arena: self.arena) } diff --git a/Tests/SwiftParserTest/DeclarationTests.swift b/Tests/SwiftParserTest/DeclarationTests.swift index 76a9d8ed9a4..8780eb3cc01 100644 --- a/Tests/SwiftParserTest/DeclarationTests.swift +++ b/Tests/SwiftParserTest/DeclarationTests.swift @@ -1552,6 +1552,15 @@ final class DeclarationTests: XCTestCase { """ ) } + + func testDoubleRightAngle() { + assertParse( + "func foo1️⃣> test()", + diagnostics: [ + DiagnosticSpec(message: "unexpected code '> test' before parameter clause") + ] + ) + } } extension Parser.DeclAttributes {