Skip to content

[5.10] [Sema] Fix try/await handling for if/switch expressions #68801

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

Conversation

hamishknight
Copy link
Contributor

5.10 cherry-pick of #68765

  • Explanation: Fixes an issue where try and await could be used to "cover" throwing and async calls within the branches of an if/switch expression. This patch fixes the issue such that we require try and await to appear on the effectful calls in the branches, and diagnose the use of try/await on an if/switch expression.
  • Scope: Affects effect type-checking around if/switch expressions
  • Issue: rdar://116066748
  • Risk: Low, the fix is fairly straightforward, and I have added a plethora of tests to ensure it works correctly
  • Testing: Added tests to test suite
  • Reviewer: Pavel Yaskevich

Previously we allowed an attached `try` or `await`
on an `if`/`switch` expression to cover the branches,
which does not match what was proposed, and is
especially harmful for multi-statement cases. Fix
the effect handling logic such that we reset
effect coverage for `if`/`switch` expressions
similar to closures, but continue to maintain the
state needed for rethrows checking.

rdar://116066748
@hamishknight hamishknight added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.10 labels Sep 27, 2023
@hamishknight hamishknight requested a review from a team as a code owner September 27, 2023 09:46
@hamishknight
Copy link
Contributor Author

@swift-ci please test

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.10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants