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-6108] "ambiguous use" on generic method after migration to swift 4 #48663
Comments
Looks like like a problem with ranking in the swift-version 4 mode because in compatibility mode we still find both of the solutions but somehow `test<T0, T1, TRet>` ranks higher than `test<T0, TRet>`. I'll try to take a closer look at this soon. |
Comment by Petro Korienev (JIRA) Observing similar issue, argument labels make the difference, this can be considered as temporary workaround: https://gist.github.com/soxjke/6c2dff8a8c255ff386f3c325d09300cf |
Comment by Sebastian Shanus (JIRA) Hi there! Any update on this issue? This is currently blocking our DI framework from upgrading to swift4 because we generate factory functions like: ``` public func to<P_1>(factory: @escaping (P_1) public func to<P_1,P_2>(factory: @escaping (P_1,P_2) ``` etc. |
sebastianv1 (JIRA User) Unfortunately you'd have to use a workaround for now, by adding labels as suggested or changing function names, ideally we'd have the second overload to match unambiguously but we need to do more refactoring of function type representation to get there. |
Comment by Jeremy Lew (JIRA) I ran into the same problem, and stumbled across a workaround that is (for my purposes) nicer than disambiguating via naming. Take the original repro code above, and alter it as follows: func test<T0, TRet>( fn: (T0) -> TRet) -> Void After this change, test(fn2) compiles and calls the test<T0,T1,TRet> It seems like the compiler is able to treat a function with N arguments as a function with one N-way-tuple argument. Hence, both the (T0) -> TRet and (T0,T1) -> TRet overloads are candidates for fn2, and the call is ambiguous. Adding 2nd pair of parens ((T0)) -> TRet limits that overload to an argument with a single parameter or 1-way tuple. sebastianv1 (JIRA User): My problem was with a DI framework as well, perhaps this will help your case. |
Environment
xcode 8.0.2, swift 3.0.2.
xcode 9, swift 4 results.
Additional Detail from JIRA
md5: abbf0f3a13f9cc840bd37a00ebc73850
Issue Description:
This is a follow up to my stackoverflow question:
https://stackoverflow.com/questions/46649106/ambiguous-use-on-generic-method-after-migration-to-swift-4
I am trying to migrate my code from xcode 8.2 swift 3.0.2 to xcode 9 swift 4, and i have problem with this code:
xcode 8.0.2, swift 3.0.2 results with:
xcode 9, swift 4 results with:
Am I missing something? Is there any new feature in swift 4 that causes this error?
The text was updated successfully, but these errors were encountered: