Skip to content

[Dynamic Casting] Allow casts to "more optional" types #33684

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

tbkka
Copy link
Contributor

@tbkka tbkka commented Aug 28, 2020

Generally, casting consistency demands that we be able to extract anything from an existential that can be put into that existential. (Which is why the casting spec requires that casting permit arbitrary injection and projection of optionals.)

This particular diagnostic prevented optionals from being projected back out of existentials:

   let i: Int?
   let a: Any = i  // Inject Int? into Any
   // Diagnostic prevents projecting Int? back out of Any
   a as? Int?

This also broke certain uses of Mirror (weak variables get reflected as
optionals stored in Any existentials).

Generally, casting consistency demands that we be able
to extract anything from an existential that can be put
into that existential.  (Which is why the casting spec
requires that casting permit arbitrary injection and
projection of optionals.)

This particular diagnostic prevented optionals from being
projected back out of existentials:
   let i: Int?
   let a: Any = i  // Inject Int? into Any
   // Error prevents projecting Int? back out of Any
   a as? Int?

This also broke certain uses of Mirror (weak variables get reflected as
optionals stored in Any existentials).
@tbkka tbkka requested review from slavapestov and jckarter August 28, 2020 16:38
@tbkka
Copy link
Contributor Author

tbkka commented Aug 28, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 238ecbf

@tbkka
Copy link
Contributor Author

tbkka commented Aug 28, 2020

@swift-ci Please test Linux platform

@tbkka tbkka merged commit 82c43a8 into swiftlang:master Sep 1, 2020
@tbkka tbkka deleted the tbkka/dynamicCastRework-optionalInjection branch October 16, 2020 00:32
@tbkka tbkka mentioned this pull request Jan 5, 2021
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.

2 participants