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-708] error: cannot convert value of type '[A]' to expected argument type '[_]' #43323

Closed
josephlord opened this issue Feb 10, 2016 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@josephlord
Copy link

Previous ID SR-708
Radar None
Original Reporter @josephlord
Type Bug
Status Closed
Resolution Cannot Reproduce
Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: b6a7bfccdf145fb9929447f3e6e64035

Issue Description:

Unhelpful error points to wrong argument.

I get the error:

cannot convert value of type '[Int]' to expected argument type '[_]'
let d = Broken<Int>(items: numbers, block: {  })
                           ^~~~~~~

With the following code when the error is the block is incorrect closure for one with arguments.

class Broken<T> {
    init(items:[T],
    block:(Int)->Void) {
    }
}
let numbers = [1,2,3,4]

let d = Broken<Int>(items: numbers, block: {  })

If the case above the error can be fixed by changing the closure to `{ _ in }`

In some more complicated cases I have found an explicit return is needed in a closure that returns Void. I don't have that well minimised at this point though.

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 8, 2016

Comment by Barbara Rodeker (JIRA)

I'd like to add more information I've found, while trying to find information about a similar error type.
This person is also experiencing this same issue.
Unhelpful error pointing to a different argument.
Please see: Cannot convert value of type 'T?' to expected argument type '_?' - Generic types and completion blocks

@mdiep
Copy link
Contributor

mdiep commented Jun 15, 2018

Swift 4.2 gives a very helpful error:

error: contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored
let d = Broken<Int>(items: numbers, block: {  })
                                           ^
                                             _ in

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants