Skip to content

[ASTScope] Allow try in unfolded sequence to cover following elements#80461

Merged
hamishknight merged 2 commits into
swiftlang:mainfrom
hamishknight:in-sequence
Apr 3, 2025
Merged

[ASTScope] Allow try in unfolded sequence to cover following elements#80461
hamishknight merged 2 commits into
swiftlang:mainfrom
hamishknight:in-sequence

Conversation

@hamishknight

Copy link
Copy Markdown
Contributor

Rather than fixing-up in the parser, adjust the ASTScope logic such that a try element in a SequenceExpr is considered as covering all elements to the right of it. Cases where this isn't true are invalid, and will be diagnosed during sequence folding. e.g:

0 * try foo() + bar()
_ = try foo() ~~~ bar() // Assuming `~~~` has lower precedence than `=`

This ensures we correctly handle try in assignment sequences, and allows ASTGen to get the behavior for free.

rdar://132872235

Use this to query for `try`-like expressions when it comes to binary
operator folding.
Rather than fixing-up in the parser, adjust the ASTScope logic such
that a `try` element in a SequenceExpr is considered as covering all
elements to the right of it. Cases where this isn't true are invalid,
and will be diagnosed during sequence folding. e.g:

```
0 * try foo() + bar()
_ = try foo() ~~~ bar() // Assuming `~~~` has lower precedence than `=`
```

This ensures we correctly handle `try` in assignment sequences, and
allows ASTGen to get the behavior for free.

rdar://132872235
@hamishknight

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@hamishknight

Copy link
Copy Markdown
Contributor Author

@swift-ci please test source compatibility

@DougGregor DougGregor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great. I love getting this out of the parser and into scope handling, thank you!

@hamishknight hamishknight merged commit 918d4b5 into swiftlang:main Apr 3, 2025
@hamishknight hamishknight deleted the in-sequence branch April 3, 2025 19:23
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.

2 participants