Skip to content

Commit 0f8240d

Browse files
committed
Braces following a variable declaration with no initializer clause are accessors
Fixes rdar://134877843, a regression introduced recently as part of the fix to swiftlang/swift#76089.
1 parent 9e15f21 commit 0f8240d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Sources/SwiftParser/Declarations.swift

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

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

Tests/SwiftParserTest/DeclarationTests.swift

+11
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,17 @@ final class DeclarationTests: ParserTestCase {
22932293
)
22942294
}
22952295

2296+
func testVariableGetSetNextLine() {
2297+
assertParse(
2298+
"""
2299+
struct X {
2300+
var x: Int
2301+
{ 17 }
2302+
}
2303+
"""
2304+
)
2305+
}
2306+
22962307
func testVariableFollowedByReferenceToSet() {
22972308
assertParse(
22982309
"""

0 commit comments

Comments
 (0)