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-10194] Ambiguous use of operator '>>' #52594
Comments
Looks like this problem has been caused by a new deprecated overload of `withUnsafeMutableBytes` method added by this commit - d030354 Since we don't rank down deprecated overloads this makes your expression truly ambiguous. |
This is the overload in question https://github.com/apple/swift/blob/master/stdlib/public/Darwin/Foundation/Data.swift#L2169 |
Honestly if we are to move full steam ahead without breaking binary compatibility we need to deprecate and replace. It seems to me the compiler should down rank deprecated overloads. |
I need to break this apart more. Often times the compiler just flakes out with blocks and the diagnostic. |
The choice not to down rank deprecated overloads has been a deliberate one, since we'd want the code to use the old overload if possible. Diagnostic about `>>` is indeed an incorrect one unfortunately, but should point to `withUnsafeMutableBytes` instead. |
Perhaps if the decision was made explicitly then it would be useful to have an attribute to mark them as less desirable by the solver. The deprecated method in question was marked that way not because we wanted a new interface only, it was deprecated because the old one was really unsafe (like wrong and could lead to undefined behavior and other nasties). |
I don't see what the ambiguity here has anything to do with our changes. The issue in question is |
@itaiferber The problem is that type-checker now finds 4 solutions related to `withUnsafeMutableBytes`, 3 of them have the same overload (and different overloads for `>>`): ``` The forth however has this overload: ``` and overload of `>>` picked from protocol requirement on BinaryInteger Which makes this ambiguous. |
After further discussion with @itaiferber we came to an understanding that unfortunately there is no way to resolve this issue because type-checker can't really distinguish this properly and old overload can't be obsoleted in Foundation. You'd have to use a temporary variable as a workaround. |
> Perhaps if the decision was made explicitly then it would be useful to have an attribute to mark them as less desirable by the solver. Can we use the |
I'd rather not because that's not something we'd like to keep. |
Environment
Apple Swift version 5.0 (swiftlang-1001.0.69.3 clang-1001.0.47).
Tested on macOS and iOS Plattform
Additional Detail from JIRA
md5: 432c1bba1617d7e8b17ff3a3c8b89b01
Issue Description:
Since swift 5 the following code breaks with "Ambiguous use of operator '>>'". In swift 4.2.1 this code works.
The text was updated successfully, but these errors were encountered: