Skip to content

Commit 06f123a

Browse files
authored
Merge pull request #3171 from rintaro/accessor-disambiguation-rdar140943107
[SwiftParse] Update for accessor block disambiguation marker
2 parents ccfe3fc + efab59f commit 06f123a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Sources/SwiftParser/Lookahead.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ extension Parser.Lookahead {
274274
var lookahead = self.lookahead()
275275
lookahead.eat(.leftBrace)
276276

277+
// '@_accessorBlock' is a builtin disambiguation marker.
278+
if lookahead.peek(isAt: .identifier),
279+
lookahead.peek().tokenText == "_accessorBlock"
280+
{
281+
return true
282+
}
283+
277284
// Eat attributes, if present.
278285
while lookahead.consume(if: .atSign) != nil {
279286
guard lookahead.consume(if: .identifier) != nil else {

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3768,4 +3768,41 @@ final class UsingDeclarationTests: ParserTestCase {
37683768
"""
37693769
)
37703770
}
3771+
3772+
func testAccessorBlockDisambiguationMarker() {
3773+
assertParse(
3774+
"""
3775+
var value = initialValue { @_accessorBlock
3776+
get
3777+
}
3778+
""",
3779+
substructure: VariableDeclSyntax(
3780+
bindingSpecifier: .keyword(.var),
3781+
bindings: [
3782+
PatternBindingSyntax(
3783+
pattern: IdentifierPatternSyntax(identifier: .identifier("value")),
3784+
initializer: InitializerClauseSyntax(
3785+
value: DeclReferenceExprSyntax(baseName: .identifier("initialValue"))
3786+
),
3787+
accessorBlock: AccessorBlockSyntax(
3788+
leftBrace: .leftBraceToken(),
3789+
accessors: .accessors([
3790+
AccessorDeclSyntax(
3791+
attributes: [
3792+
.attribute(
3793+
AttributeSyntax(
3794+
atSign: .atSignToken(),
3795+
attributeName: IdentifierTypeSyntax(name: .identifier("_accessorBlock"))
3796+
)
3797+
)
3798+
],
3799+
accessorSpecifier: .keyword(.get)
3800+
)
3801+
])
3802+
)
3803+
)
3804+
]
3805+
)
3806+
)
3807+
}
37713808
}

0 commit comments

Comments
 (0)