Skip to content

[6.2] [Sema] Continue type-checking for body when preamble fails #81554

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 1 commit into from
May 16, 2025

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented May 16, 2025

6.2 cherry-pick of #81540

  • Explanation: Fixes a crash that could occur when forming an autoclosure in a variable binding in the body of an invalid for loop
  • Scope: Affects for loop type-checking
  • Issue: rdar://136500008
  • Risk: Medium - This does change a pretty fundamental part of how for loops are type-checked, but I don't actually think the risk is too bad since:
    • It only affects invalid code
    • We were already doing some amount of downstream type-checking through request evaluation for e.g pattern bindings
    • The situation today is already pretty bad since it can be triggered by something as simple as let x = foo && bar in the body of an invalid loop
  • Testing: Added tests to test suite
  • Reviewer: Pavel Yaskevich

Skipping type-checking the body when the preamble fails to type-check
seems to be more of a historical artifact than intentional behavior.
Certain elements of the body may still get type-checked through
request evaluation, and as such may introduce autoclosures that won't
be properly contextualized. 

Make sure we continue type-checking the body even if the preamble
fails. We already invalidate any variables bound in the element
pattern, so downstream type-checking should be able to handle it
just fine. This ensures autoclosures get contextualized, and that
we're still able to provide semantic diagnostics for other issues in
the body.

rdar://136500008
@hamishknight hamishknight requested review from bnbarham and hborla May 16, 2025 13:11
@hamishknight hamishknight requested a review from a team as a code owner May 16, 2025 13:11
@hamishknight hamishknight added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2 labels May 16, 2025
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight merged commit d7286eb into swiftlang:release/6.2 May 16, 2025
5 checks passed
@hamishknight hamishknight deleted the last-straw-6.2 branch May 16, 2025 22:57
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 6.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants