Skip to content

Commit 8152850

Browse files
ahoppenrjmccall
authored andcommitted
Correctly skip arguments to @convention attribute
Fixes #2474 rdar://122358055
1 parent f8c3ccc commit 8152850

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

Sources/SwiftParser/Lookahead.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,11 @@ extension Parser.Lookahead {
162162
if let (attr, handle) = self.at(anyIn: TypeAttribute.self) {
163163
// Ok, it is a valid attribute, eat it, and then process it.
164164
self.eat(handle)
165-
if case .convention = attr {
166-
guard
167-
self.consume(if: .leftParen) != nil,
168-
self.consume(if: .identifier) != nil,
169-
self.consume(if: .rightParen) != nil
170-
else {
171-
return
172-
}
165+
switch attr {
166+
case .convention:
167+
self.skipSingle()
168+
default:
169+
break
173170
}
174171
return
175172
}

Tests/SwiftParserTest/AttributeTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,4 +886,25 @@ final class AttributeTests: ParserTestCase {
886886
"""
887887
)
888888
}
889+
890+
func testConventionAttributeInArrayType() {
891+
assertParse(
892+
"""
893+
_ = [@convention(c, cType: "int (*)(int)") (Int32) -> Int32]()
894+
""",
895+
substructure: ConventionAttributeArgumentsSyntax(
896+
conventionLabel: .identifier("c"),
897+
comma: .commaToken(),
898+
cTypeLabel: .keyword(.cType),
899+
colon: .colonToken(),
900+
cTypeString: StringLiteralExprSyntax(
901+
openingQuote: .stringQuoteToken(),
902+
segments: StringLiteralSegmentListSyntax([
903+
StringLiteralSegmentListSyntax.Element(StringSegmentSyntax(content: .stringSegment("int (*)(int)")))
904+
]),
905+
closingQuote: .stringQuoteToken()
906+
)
907+
)
908+
)
909+
}
889910
}

0 commit comments

Comments
 (0)