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-8347] ambiguous subscript when used in “if let" #50875
Comments
I think this is a good idea, and implementing it is fairly straightforward: gregomni@4c6c867 (that's just a proof of concept – a real implementation would have a bunch of tests and assert that you don't try to also pass in a specific contextual type along with the added must-be-optional flag and so on...) Is this a swift-evolution proposal thing? a go ahead and complete this and pull request thing? or a bad idea for some reason that hasn't occurred to me yet? @xedin or @rudkx thoughts maybe? Thanks! |
Thanks Greg! I’ve checked your patch on my build and this solves the problem I was looking at. Do you want to file a PR on apple/swift? Let me know if you want me to write a test. I‘m hoping this is more of a bug fix than something that needs to be evolved given the alternative is currently an error. Perhaps it might even sneak under the wire for 4.2… |
John, I am happy to firm this up and file a PR, and that seems like a reasonable way forward to me. But the Apple people are the ones who get complaints if somebody out there is accidentally depending upon some quirk of the typechecker that changes out from under them, so I'm trying to learn to be slightly more cautious. 🙂 |
Agreed, I may be getting ahead of myself. Tweaking the typechecker is an activity for the brave. The first step is to get the PR into the queue and see what the compiler devs think along with a CI test run. Thanks for your help on this! |
I also think this is a good idea, don't think it should cause any problems with existing code, and I don't think it would need a full SE proposal, but I think it's reasonable to bring that question up on the Evolution | Discussion forum. |
+1 to @rudkx |
Cool. Brought up on Evolution | Discussion and PR: #18188 |
Great, thanks Greg. Let’s see if someone picks it up. |
Thanks again for the time you put into this Greg. From idle thought to “master" in under a week! |
Thanks John! |
Environment
Xcode 9.4.1 -> master
Additional Detail from JIRA
md5: 41f20c0680877ef67d4e523a9482b6d5
Issue Description:
I have a struct on which I’d like to define two subscript operations
These are unambiguous if I provide context such as ! or ?? or a type
But not if I use the expression in an if let which implies the expression must be an optional and gives an error if it’s not.
I need to do the following :
This isn’t the biggest of deals but if an easy way could be found for when an expression is being used in an if let the compiler could propagate a constraint to the type checker that the result needs to be an optional that would be great.
The text was updated successfully, but these errors were encountered: