Skip to content

[4.2][Sema] Restrict new optional-to-archetype casting behaviour to Swift 5 mode #19562

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

Conversation

hamishknight
Copy link
Contributor

(4.2 cherry-pick of #19217)

  • Explanation: Limits a behavioural change to Swift 5 mode where we're now more conservative with unwrapping of an optional value when casting it to a generic placeholder type.

  • Scope: Resolves a 4.2 compatibility regression, limiting the new behaviour to Swift 5 mode.

  • SR Issue: SR-8704.

  • Risk: Low – this restores the old casting behaviour (prior to [Sema] Don't treat archetypes as non-optional when casting to them #13910) in -swift-version 4 & -swift-version 4.2.

  • Testing: Added tests for Swift 4 casting behaviour, Test suite, Compatibility suite.

  • Reviewers: @slavapestov, @DougGregor.

…5 mode

In swiftlang#13910, the behaviour of optional-to-archetype casts changed such that we're now more conservative with the unwrapping of the operand at compile time in order to account for the fact that an optional type could be substituted at runtime. This brought such casting behaviour inline with that in a non-generic context, however it wasn't properly gated by Swift version, leading to compatibility issues.

This commit restricts the new behaviour to Swift 5 mode and above.

Resolves SR-8704.
@rudkx
Copy link
Contributor

rudkx commented Sep 26, 2018

@swift-ci please test

@tkremenek
Copy link
Member

I sincerely apologize for now seeing this sooner, and I appreciate you filing the PR.

Swift 4.2.1 is a very focused release, and there are always a chance of regressions being introduced by changes like this. We should hold this fix to Swift 5.

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