-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Add warning for ambiguous value assignment when using Optional #21621
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
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.
Overall, I think this is supposed to be an error instead of a warning but warning is better than nothing.
It seems like it could only happen in expression context, so maybe it would make sense for this warning to be produced by the constraint solver instead? You can take a look at ExprRewritter::visitUnresolvedMemberExpr
, I think it would be reasonable to put that check there if the base was optional type.
Also it might be reasonable to mention member name as well e.g. enum case
.noneexists in both 'E' and
Optional, picked the one from 'Optional<E>'
or something like that...
A warning is our only choice since an error would create a source compatibility issue. Here's a test case demonstrating that it needs to happen in CSApply's ExprRewriter and not when checking the initial value of a property:
|
@slavapestov @xedin done 👍 |
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.
I have a lot of suggestions, but this is a really solid start!
@slavapestov can you invoke the CI again? |
@swift-ci please smoke test |
Seems like I should've attached the fix-it to the @xedin can you invoke the CI now? The tests should now pass 🙏 |
@swift-ci please smoke test |
The column numbers I used for the fixits differed by 1 🤦♂️ @xedin can you invoke the CI once again? Thanks 😄 |
@swift-ci please smoke test |
All tests have passed 🎉 @xedin |
@swift-ci please smoke test |
This issue is best explained with an example:
This PR fixes this issue by diagnosing it as a warning and offering two fixits: prefix
Optional
or prefix the explicit type to silence the warning.Resolves SR-2176, SR-3711, SR-6044, SR-8283, SR-8451 & SR-8515.
Resolves rdar://problem/26126801.