Skip to content

Commit c605f07

Browse files
committed
Fix Regression in Actor Disambiguation
1 parent 7c73511 commit c605f07

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
@_spi(RawSyntax) import SwiftSyntax
1414

1515
extension TokenConsumer {
16-
func atStartOfDeclaration(isAtTopLevel: Bool = false, allowRecovery: Bool = false) -> Bool {
16+
func atStartOfDeclaration(
17+
isAtTopLevel: Bool = false,
18+
allowRecovery: Bool = false
19+
) -> Bool {
1720
if self.at(anyIn: PoundDeclarationStart.self) != nil {
1821
return true
1922
}
@@ -54,6 +57,19 @@ extension TokenConsumer {
5457
declStartKeyword = subparser.at(anyIn: DeclarationStart.self)?.0
5558
}
5659
switch declStartKeyword {
60+
case .actorContextualKeyword:
61+
// actor Foo {}
62+
if subparser.peek().tokenKind == .identifier {
63+
return true
64+
}
65+
// actor may be somewhere in the modifier list. Eat the tokens until we get
66+
// to something that isn't the start of a decl. If that is an identifier,
67+
// it's an actor declaration, otherwise, it isn't.
68+
var lookahead = subparser.lookahead()
69+
repeat {
70+
lookahead.consumeAnyToken()
71+
} while lookahead.atStartOfDeclaration()
72+
return lookahead.at(.identifier)
5773
case .caseKeyword, nil:
5874
// When 'case' appears inside a function, it's probably a switch
5975
// case, not an enum case declaration.

Tests/SwiftParserTest/Statements.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ final class StatementTests: XCTestCase {
9191
}
9292

9393
func testReturn() {
94+
AssertParse("return actor", { $0.parseReturnStatement() })
95+
9496
AssertParse("{ #^ASYNC^#return 0 }",
9597
{ $0.parseClosureExpression() },
9698
substructure: Syntax(ReturnStmtSyntax(returnKeyword: .returnKeyword(),

0 commit comments

Comments
 (0)