From efab59f96b9c05f6a335e861ce9967bb652356af Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Thu, 16 Oct 2025 16:35:45 -0700 Subject: [PATCH] [SwiftParse] Update for accessor block disambiguation marker If the block after an pattern binding initializer starts with `{ @_accessorBlock` it's an accessor block, not a trailing closure. rdar://140943107 --- Sources/SwiftParser/Lookahead.swift | 7 ++++ Tests/SwiftParserTest/DeclarationTests.swift | 37 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/Sources/SwiftParser/Lookahead.swift b/Sources/SwiftParser/Lookahead.swift index 4c16f78b8b9..90748e2cd38 100644 --- a/Sources/SwiftParser/Lookahead.swift +++ b/Sources/SwiftParser/Lookahead.swift @@ -274,6 +274,13 @@ extension Parser.Lookahead { var lookahead = self.lookahead() lookahead.eat(.leftBrace) + // '@_accessorBlock' is a builtin disambiguation marker. + if lookahead.peek(isAt: .identifier), + lookahead.peek().tokenText == "_accessorBlock" + { + return true + } + // Eat attributes, if present. while lookahead.consume(if: .atSign) != nil { guard lookahead.consume(if: .identifier) != nil else { diff --git a/Tests/SwiftParserTest/DeclarationTests.swift b/Tests/SwiftParserTest/DeclarationTests.swift index 5abae62a131..a9f07400fe0 100644 --- a/Tests/SwiftParserTest/DeclarationTests.swift +++ b/Tests/SwiftParserTest/DeclarationTests.swift @@ -3768,4 +3768,41 @@ final class UsingDeclarationTests: ParserTestCase { """ ) } + + func testAccessorBlockDisambiguationMarker() { + assertParse( + """ + var value = initialValue { @_accessorBlock + get + } + """, + substructure: VariableDeclSyntax( + bindingSpecifier: .keyword(.var), + bindings: [ + PatternBindingSyntax( + pattern: IdentifierPatternSyntax(identifier: .identifier("value")), + initializer: InitializerClauseSyntax( + value: DeclReferenceExprSyntax(baseName: .identifier("initialValue")) + ), + accessorBlock: AccessorBlockSyntax( + leftBrace: .leftBraceToken(), + accessors: .accessors([ + AccessorDeclSyntax( + attributes: [ + .attribute( + AttributeSyntax( + atSign: .atSignToken(), + attributeName: IdentifierTypeSyntax(name: .identifier("_accessorBlock")) + ) + ) + ], + accessorSpecifier: .keyword(.get) + ) + ]) + ) + ) + ] + ) + ) + } }