-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SR-2176] Add warning for ambiguous enum value assignment #44784
Comments
I'm pretty sure this can only happen with Optional, because we don't look through any other types in dot-shorthand syntax, but it still seems like a good idea to me. |
Hey, @xedin, think this is simple enough for a starter bug? It's "just" post-processing of a type-checked expression, right? |
I think so, I can help out if anybody wants to take it too. |
Comment by Kelan Champagne (JIRA) I'd love to be able to take this., especially because I reported it. But, it would be my very first Swift contribution, so I'd have a bit of a learning curve to climb. Also, coincidentally, I just started at Apple (yesterday!), so I think there are some forms I need to submit, etc before I can actually post any PRs. But, I'm really interested in learning how to do this, so if it's not urgent, I'd like to give it a shot. |
kelan (JIRA User) Sure, take your time! If you need any help please do let me know. |
Comment by Andyy Hope (JIRA) Hey kelan (JIRA User) - You still doing this? Sounds interesting 🙂 |
Comment by Kelan Champagne (JIRA) andyyhope (JIRA User)- I haven't actually started on anything for this yet. I am still interested, but there is some process I have to get through first. So, if you're excited about it – go ahead. If you're looking for StarterBugs, another one I had on my list to look at is SR-5982. Although that one looks a little more involved (but probably also more interesting). |
I've created a PR for review: #21621 |
Fixed on master. I'll cherry pick this to the 5.0 branch. |
This is fixed as of at least Swift 5.5, so I'm closing this. |
Thank you for fixing this! |
Environment
Xcode v8.0 beta 3 (8S174q)
Apple Swift version 3.0 (swiftlang-800.0.34.6 clang-800.0.33)
Target: x86_64-apple-macosx10.9
AND
Xcode v7.3.1 (7D1014)
Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31)
Target: x86_64-apple-macosx10.9
Additional Detail from JIRA
md5: 1e3b35e57d95ed4fe6d3877bd98474f4
is duplicated by:
relates to:
Issue Description:
I've been caught off-guard by the value that's chosen by the compiler when inferring the type to assign to an enum value. This can be especially surprising because
nil
is shorthand forOptional.none
.For example, if I have this enum:
Because
myCoverageA
gets a value of.some(.all)
, you might expect the value ofmyCoverageB
to be.some(.none)
, but in fact it is.none
.I think this would also come up in a double-Optional. For example:
Expect
I think it would be nice to have a compiler warning in ambiguous cases like this.
Notes
I wrote up a slightly more detailed example of this here: http://kelan.io/2016/type-inferior-ence/
The text was updated successfully, but these errors were encountered: