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-7319] Function invocations returning generics fail with ambiguous use after Swift 4.1 upgrade #49867
Comments
@iby, what is the output of running |
One that ships with latest Xcode 9.2: Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2) |
@iby, I tried your example with Xcode 9.2 (and earlier Xcodes) and see the same error about the call to I agree offhand this seems like something we should be able to disambiguate, but I don't think this is a regression from Xcode 9.2. Are you sure this code is representative of what you had compiled successfully with Xcode 9.2? |
@rudkx yes, I missed elephant in the room. Frankly, this all comes down to |
The difference in behavior here is a result of {Optional} becoming {Equatable}. Previously there was a single overload that worked for type checking: let x2: G<String?> = g1(key: "foo") but now both overloads work, and neither is considered better. |
The only workaround that comes to mind for disambiguating here is somewhat ugly. You could add a dummy protocol requirement and extensions for the (non-Optional) types that you'd like to use this with, e.g.: protocol P {} func g1<T: Equatable & P>(key: String) -> G<T> { return G() } let x2: G<String?> = g1(key: "foo") |
Thanks for looking into and suggestions. I didn't realise the issue was so broad and not just a regression. The fact that it was working all that time is just me being lucky. I'll refactor the code, but I think it's a good idea to be able to disambiguate these things. |
Yes I agree it would be good if we could find a principled way to disambiguate here. Thanks for reporting this. |
Attachment: Download
Additional Detail from JIRA
md5: 3f77184580bbb57ed556d04b7eaea88e
Issue Description:
This code used to work yesterday:
Now it reports:
It appears it doesn't see difference between optional and non-optional generic parameters in return and treats them equally. This however doesn't apply to regular optional/non-optional generic return type – it invokes correct function in case with
g2
. Changing function signature makes this go away. Is there any other workaround?The text was updated successfully, but these errors were encountered: