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-9800] Ambiguity with calling UnsafePointer(someMutablePointer) #52224
Comments
Explicitly specifying |
SE-0205 doesn't look related to me; that introduces overloads of |
`public init(_ other: Self)` part is not clear to me, but the expression seems ambiguous. Since there is an initializer that converts any `UnsafeMutablePointer<T>` into any other `UnsafePointer<U>`, and multiple functions accepting various UnsafePointer's which one should be chosen? Maybe an invalid diagnostic, but the behavior looks correct to me. |
Oh you're right, the real issue here is that there now exists an I think that's incorrect. This completely backtracks on the whole memory-rebinding stuff we introduced before. And from the docstring it seems to have been a mistake:
This docstring suggests that the initializer was moved from |
I think this is something which has been fixed in 5 to be ambiguous and previous behavior was due to the solver trying overloads in the different order (init before foo) which incorrectly filtered out one of the partial solutions. |
Among other things, this initializer lets me write stuff like var s = "foo"
let x = UnsafePointer<Int>(&s) which is clearly wrong. |
Or there is a new overload which makes this ambiguous 🙂 |
Looks like this was introduced in #17952 |
Ping PR is merged but this still open, should this be resolved? 🙂 |
Indeed this should be resolved, thanks, @LucianoPAlmeida! Please verify using a snapshot of master and close. |
Environment
Apple Swift version 5.0 (swiftlang-1001.0.45.7 clang-1001.0.37.7)
Target: x86_64-apple-darwin18.2.0
ABI version: 0.6
Xcode 10.2 beta (10P82s)
Additional Detail from JIRA
md5: 65cb31e64243a6f3b139ee42c7599890
Issue Description:
If I have code that converts an
UnsafeMutablePointer
to anUnsafePointer
and passes the result to an overloaded function that takes multiple types ofUnsafePointer
(such asString.init(cString:)
) this throws an ambiguity error with the Swift 5 compiler. This seems to be a straight-up bug in method resolution because one of the two methods it thinks is ambiguous isUnsafePointer.init(_ other: Self)
, even though that can't possibly apply as the argument is anUnsafeMutablePointer
.Reproduction:
This compiles with the Swift 4.2 compiler, but with the Swift 5 compiler (even in Swift 4 mode) it throws an error:
The text was updated successfully, but these errors were encountered: