Skip to content

[5.9] Handle #if for if/switch expressions #65347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2023

Conversation

hamishknight
Copy link
Contributor

5.9 cherry-pick of #65098

  • Explanation: Allows if/switch expressions to work with #if blocks, both in implicit return position, and as branches when there is a single active expression.
  • Scope: Affects type-checking of if/switches when used with #if blocks.
  • Issue: rdar://107487977
  • Risk: Low/Medium, should only affect code that would otherwise be invalid, except for the one case of mismatching Void/Void? branches in closures that we are already aware of.
  • Testing: Added tests to test suite.
  • Reviewers: Pavel Yaskevich, Alex Hoppen

Use this to replace
`Parser::shouldReturnSingleExpressionElement`.
This should be NFC.
Previously we would say that it must end with a
`throw`, but a more useful diagnostic is that
there is an expression missing.
- Allow an if/switch expression to become an
implicit return of a function that has a `#if`
body with a single active element that is an `if`
or `switch`.
- Allow `#if` branches of an if/switch expression,
as long as there is a single active expression
element.

rdar://107487977
@hamishknight hamishknight requested a review from a team as a code owner April 21, 2023 09:32
@xedin xedin added the 🍒 release cherry pick Flag: Release branch cherry picks label May 1, 2023
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight merged commit aa695c3 into swiftlang:release/5.9 May 4, 2023
@hamishknight hamishknight deleted the poundland-5.9 branch May 4, 2023 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants