Skip to content

Commit 3bf88ba

Browse files
committed
Parse Opaque Return Type Attributes Correctly
1 parent bc256a7 commit 3bf88ba

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

Sources/SwiftParser/Attributes.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,22 @@ extension Parser {
773773
}
774774
}
775775

776+
extension Parser {
777+
mutating func parseOpaqueReturnTypeOfAttributeArguments() -> RawOpaqueReturnTypeOfAttributeArgumentsSyntax {
778+
let (unexpectedBeforeString, mangledName) = self.expect(.stringLiteral)
779+
let (unexpectedBeforeComma, comma) = self.expect(.comma)
780+
let (unexpectedBeforeOrdinal, ordinal) = self.expect(.integerLiteral)
781+
return RawOpaqueReturnTypeOfAttributeArgumentsSyntax(
782+
unexpectedBeforeString,
783+
mangledName: mangledName,
784+
unexpectedBeforeComma,
785+
comma: comma,
786+
unexpectedBeforeOrdinal,
787+
ordinal: ordinal,
788+
arena: self.arena)
789+
}
790+
}
791+
776792
// MARK: Lookahead
777793

778794
extension Parser.Lookahead {

Sources/SwiftParser/Types.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,26 @@ extension Parser {
820820
arena: self.arena
821821
)
822822
)
823+
case ._opaqueReturnTypeOf:
824+
let (unexpectedBeforeAt, at) = self.expect(.atSign)
825+
let ident = self.expectIdentifierWithoutRecovery()
826+
let (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
827+
let argument = self.parseOpaqueReturnTypeOfAttributeArguments()
828+
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
829+
return RawSyntax(
830+
RawAttributeSyntax(
831+
unexpectedBeforeAt,
832+
atSignToken: at,
833+
attributeName: ident,
834+
unexpectedBeforeLeftParen,
835+
leftParen: leftParen,
836+
argument: RawSyntax(argument),
837+
unexpectedBeforeRightParen,
838+
rightParen: rightParen,
839+
tokenList: nil,
840+
arena: self.arena
841+
)
842+
)
823843

824844
default:
825845
let (unexpectedBeforeAt, at) = self.expect(.atSign)

Tests/SwiftParserTest/Types.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,11 @@ final class TypeTests: XCTestCase {
5959
DiagnosticSpec(message: "Unexpected text '`' found in closure capture signature")
6060
])
6161
}
62+
63+
func testOpaqueReturnTypes() throws {
64+
AssertParse("""
65+
public typealias Body = @_opaqueReturnTypeOf("$s6CatKit10pspspspspsV5cmereV6lilguyQrvp", 0) __
66+
""")
67+
}
6268
}
69+

0 commit comments

Comments
 (0)