Skip to content
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-5931] incorrect error message "'UnsafePointer<UInt8>' is not convertible to 'UnsafePointer<_>'" #48490

Open
swift-ci opened this issue Sep 19, 2017 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-5931
Radar None
Original Reporter comex (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 5879afa706162516f67d24b564cacb9a

Issue Description:

The following code:

import Foundation
func appendFirstFiveBytes(of source: Data, to target: inout Data) {
    source.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) in
        target.append(ptr, 5)
    }
}

…is erroneous only because the call to `target.append` is missing a `count:` label. But instead of complaining about that, swiftc produces two useless and misleading errors:

a.swift:3:30: error: 'UnsafePointer<UInt8>' is not convertible to 'UnsafePointer<_>'
    source.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) in
                             ^
a.swift:4:9: error: escaping closures can only capture inout parameters explicitly by value
        target.append(ptr, 5)
        ^

Similarly, if `count:` is added but `inout` is removed:

import Foundation
func appendFirstFiveBytes(of source: Data, to target: Data) {
    source.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) in
        target.append(ptr, count: 5)
    }
}

swiftc produces the "not convertible" error instead of complaining that `target` is immutable:

a.swift:3:30: error: 'UnsafePointer<UInt8>' is not convertible to 'UnsafePointer<_>'
    source.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) in                   

In both cases, removing the type annotation causes the correct error to be displayed, but in the first case the meaningless "escaping closures" error is still present:

a.swift:4:22: error: missing argument label 'count:' in call
        target.append(ptr, 5)
                     ^
                           count: 
a.swift:4:9: error: escaping closures can only capture inout parameters explicitly by value
        target.append(ptr, 5)
a.swift:4:9: error: cannot use mutating member on immutable value: 'target' is a 'let' constant
        target.append(ptr, count: 5)
        ^~~~~~

Tested on latest nightly.

(Probably the same as SR-2297, which I just closed because the original test case works correctly now.)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant