Skip to content

Commit 701a58b

Browse files
committed
Fix parsing error if @objc selector contains an underscore
1 parent e1ee3cf commit 701a58b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Sources/SwiftParser/Attributes.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ extension Parser {
494494
mutating func parseObjectiveCSelector() -> RawObjCSelectorSyntax {
495495
var elements = [RawObjCSelectorPieceSyntax]()
496496
var loopProgress = LoopProgressCondition()
497-
while !self.at(any: [.eof, .rightParen]) && loopProgress.evaluate(currentToken) {
497+
while loopProgress.evaluate(currentToken) {
498498
// Empty selector piece.
499499
if let colon = self.consume(if: .colon) {
500500
elements.append(
@@ -507,7 +507,7 @@ extension Parser {
507507
continue
508508
}
509509

510-
if self.at(.identifier) || self.currentToken.isKeyword {
510+
if self.at(any: [.identifier, .wildcardKeyword]) || self.currentToken.isKeyword {
511511
let name = self.consumeAnyToken()
512512

513513
// If we hit a ')' we may have a zero-argument selector.
@@ -531,6 +531,8 @@ extension Parser {
531531
arena: self.arena
532532
)
533533
)
534+
} else {
535+
break
534536
}
535537
}
536538
return RawObjCSelectorSyntax(elements: elements, arena: self.arena)

Tests/SwiftParserTest/AttributeTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ final class AttributeTests: XCTestCase {
9090
func f(_: Int, _: Int, _: Int, _: Int, _: Int) { }
9191
"""
9292
)
93+
94+
AssertParse(
95+
"""
96+
@objc(_:)
97+
func f(_: Int)
98+
"""
99+
)
93100
}
94101

95102
func testRethrowsAttribute() {

0 commit comments

Comments
 (0)