Skip to content

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Oct 16, 2025

Update for swiftlang/swift#84972
If the block after a pattern binding initializer starts with { @_accessorBlock it's an accessor block, not a trailing closure.

rdar://140943107

@rintaro
Copy link
Member Author

rintaro commented Oct 16, 2025

swiftlang/swift#84972
@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Oct 17, 2025

swiftlang/swift#84972
@swift-ci Please test

if lookahead.peek(isAt: .identifier),
lookahead.peek().tokenText == "_accessorBlock"
{
return true;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return true;
return true

lookahead.eat(.leftBrace)

// '@_accessorBlock' is a builtin disambiguation marker.
if lookahead.peek(isAt: .identifier),
Copy link
Member

Choose a reason for hiding this comment

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

Don’t you also need to consume the @ before looking at the identifier? Also, I think a test case would be good.

Also, I think this would probably belong in the while lookahead.consume(if: .atSign) != nil { loop below to make it resilient so @_accessorBlock doesn’t necessarily need to be the first attribute.

Copy link
Member Author

Choose a reason for hiding this comment

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

Don’t you also need to consume the @ before looking at the identifier?

We know the current token is @ at line 269 above.

I think this would probably belong in the while lookahead.consume(if: .atSign) != nil { loop below to make it resilient so @_accessorBlock doesn’t necessarily need to be the first attribute.

ASTPrinter only print @_accessorBlock right after {. I don't see a reason to put it in the loop

Also, I think a test case would be good.

Sure, I will add a test case.

Copy link
Member

Choose a reason for hiding this comment

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

We know the current token is @ at line 269 above.

Ah, I got a little confused about nextToken and then using a fresh lookahead here. Opened #3172 to make this slightly easier to read.

ASTPrinter only print @_accessorBlock right after {. I don't see a reason to put it in the loop

OK, your choice. But I find it odd that order of attributes matters here when it doesn’t in any other cases.

ahoppen added a commit to ahoppen/swift-syntax that referenced this pull request Oct 17, 2025
I think the guard is a lot easier to read here, noticed while reviewing swiftlang#3171.
If the block after an pattern binding initializer starts with
`{ @_accessorBlock` it's an accessor block, not a trailing closure.

rdar://140943107
@rintaro rintaro force-pushed the accessor-disambiguation-rdar140943107 branch from f5c167e to efab59f Compare October 17, 2025 16:51
@rintaro
Copy link
Member Author

rintaro commented Oct 17, 2025

swiftlang/swift#84972
@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Oct 17, 2025

swiftlang/swift#84972
@swift-ci Please test Windows

@rintaro rintaro merged commit 06f123a into swiftlang:main Oct 18, 2025
34 checks passed
ahoppen added a commit to ahoppen/swift-syntax that referenced this pull request Oct 19, 2025
I think the guard is a lot easier to read here, noticed while reviewing swiftlang#3171.
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