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-11400] Error when nil coalessing multiple types with common protocol #53801
Comments
@swift-ci create |
The problem here as correctly mentioned @CraigSiemens is related to the fact that we don't unify types by their protocol conformances unless that protocol is explicitly specified, that's why e.g. `A() ?? B()` can't be type-checked into ??<P>(A?, B?) because of that. This is expected behavior. |
We have an explicitly-specified protocol: the result type. |
For the simplest comparison, |
@belkadan It might work for a single operator but not for linked operators, binding collections can't really propagate contextual type which means that bindings for arguments would never have `P` as a possible type. We have talked about attempting protocols before but it leads to other failures. Unfortunately we can't solve this without rework of how solver infers possible types for type variables. |
I don't know what you mean by "linked operators" or "collections". There are no collection literals here and all of the working examples Craig provides show that this is clearly a bug. It may be hard to fix, but it's hardly invalid. |
I mean expressions like "1 + 2 + 3" where result of one operator is an argument to another one. This is a problem which might always require specifying protocol explicitly because fixing it means a revamp of the solver. |
Additional Detail from JIRA
md5: bd4fbe3801df07312c08103c2d7c0509
Issue Description:
I've got multiple types that conform to the same protocol and I'm trying to use the nil coalescing operator to get the first one where the failable initializer succeeds. Heres and example that shows it off in a playground.
The full console output I get is
It feels like it should work but the compiler is complaining about it. The weird thing is there's a couple simple workarounds
The text was updated successfully, but these errors were encountered: