-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Typechecker] Warn when casting a function type to an existential or archetype type #22822
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
cc @jrose-apple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true. A function type can be unconditionally cast to an 'Any'.
It can also be conditionally cast to a generic parameter with no constraints; the cast will succeed if that generic parameter happens to be bound to an identical function type at runtime.
@slavapestov Oh right, I should update my comment. If you cast it to This is only for a force-cast and not an conditional cast, but I can extend it to cover the latter scenario. |
Can you add an assert that you don't get an 'Any' here, and make sure the tests cover the correct behavior? Conditional-cast and force-cast have the same semantics regarding what casts can ever succeed or not. So a conditional-cast of a function type to a non-Any existential should also warn that it will always fail. Similarly, both a force-cast and a conditional-cast of a function type to an unconstrained archetype is OK. |
AnyObject should also behave like Any, since it's basically "Any but box it up if you have to". |
@slavapestov Done, does it look good to you? |
@jrose-apple That's already handled, so you will get the |
…o protocol type/archetype type
Running tests for you, still waiting on Slava for final OK. @swift-ci Please test |
Thanks Jordan, all tests have passed 🎉 @slavapestov @xedin does this look okay to you? |
Bump. Is this good to merge now? |
@slavapestov Can you invoke the CI again? |
@swift-ci please test |
Build failed |
Build failed |
OSX build failed with |
@swift-ci Please smoke test macOS |
The smoke test passed! Do we need to run a full OSX test as well or is this good to merge without it? |
This PR extends the unrelated downcast warning to cast from a function type to an existential type or a archetype type. If the referenced function has a non-void return type, then a fix-it is offered to call the function instead.
Resolves SR-6022.
Resolves rdar://problem/25723751