Skip to content

Handle #if for if/switch expressions #65098

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
Apr 21, 2023

Conversation

hamishknight
Copy link
Contributor

  • 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

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
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Looks good to me. I did not look through the test cases trusting though, trusting that you covered everything correctly.

@hamishknight
Copy link
Contributor Author

Source compat failures match those on main.

@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight merged commit 017794a into swiftlang:main Apr 21, 2023
@hamishknight hamishknight deleted the poundland branch April 21, 2023 08:26
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