Skip to content

Commit 9e15f21

Browse files
committed
Don't always treat a closure following a variable declaration as an accessor block
Introduce some lookahead to make sure we actually have something that looks like an accessor block when the `{` is on the next line, matching what the C++ parser does. Fixes swiftlang/swift#76089
1 parent 0aaea2a commit 9e15f21

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Sources/SwiftParser/Declarations.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,8 @@ extension Parser {
13541354
}
13551355

13561356
let accessors: RawAccessorBlockSyntax?
1357-
if self.at(.leftBrace)
1357+
if (self.at(.leftBrace)
1358+
&& (!self.currentToken.isAtStartOfLine || self.withLookahead({ $0.atStartOfGetSetAccessor() })))
13581359
|| (inMemberDeclList && self.at(anyIn: AccessorDeclSyntax.AccessorSpecifierOptions.self) != nil
13591360
&& !self.at(.keyword(.`init`)))
13601361
{

Tests/SwiftParserTest/ExpressionTests.swift

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ final class ExpressionTests: ParserTestCase {
5858
}
5959
"""
6060
)
61+
62+
assertParse(
63+
"""
64+
func f(x:[Void])
65+
{
66+
var y:[[Void]] = x.map { [$0] }
67+
{
68+
$0.reserveCapacity(1)
69+
} (&y[0])
70+
}
71+
"""
72+
)
6173
}
6274

6375
func testTrailingClosures() {

0 commit comments

Comments
 (0)