Skip to content

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Oct 16, 2025

.swiftinterface sometimes prints a pattern binding initializer and the accessor block. However the parser doesn't expect such constructs and the disambiguation from trailing closures would be fragile. To make it reliable, introduce a disambiguation marker @_accessorBlock . ASTPrinter print it right after { only if 1) The accrssor block is for a pattern binding declration, 2) the decl has an initializer printed, and 3) the non-observer accessor block is being printed. In the parser, If the block after an initializer starts with { @_accessorBlock it's always parsed as an accessor block instead of a trailing closure.

rdar://140943107

@rintaro
Copy link
Member Author

rintaro commented Oct 16, 2025

swiftlang/swift-syntax#3171
@swift-ci Please smoke test

Copy link
Contributor

@tshortli tshortli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

.swiftinterface sometimes prints a pattern binding initializer and the
accessor block. However the parser doesn't expect such constructs and
the disambiguation from trailing closures would be fragile. To make it
reliable, introduce a disambiguation marker `@_accessorBlock` .
`ASTPrinter` prints it right after `{` only if 1) The accessor block is
for a pattern binding declaration, 2) the decl has an initializer
printed, and 3) the non-observer accessor block is being printed. In the
parser, if the block after an initializer starts with
`{ @_accessorBlock`, it's always parsed as an accessor block instead of
a trailing closure.

rdar://140943107
@rintaro rintaro force-pushed the accessor-disambiguation-rdar140943107 branch from 128f485 to 6a1604b Compare October 17, 2025 05:19
@rintaro
Copy link
Member Author

rintaro commented Oct 17, 2025

swiftlang/swift-syntax#3171
@swift-ci Please smoke test

1 similar comment
@rintaro
Copy link
Member Author

rintaro commented Oct 17, 2025

swiftlang/swift-syntax#3171
@swift-ci Please smoke test

@rintaro rintaro merged commit 13e1787 into swiftlang:main Oct 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants