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-11361] Collection.removeAll(where:) gives "Extra argument 'where' in call" misleading error #53762

Closed
idrougge opened this issue Aug 23, 2019 · 3 comments
Assignees
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

Comments

@idrougge
Copy link

Previous ID SR-11361
Radar None
Original Reporter @idrougge
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 10.3 (10G8), Swift 5

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee @idrougge
Priority Medium

md5: 8390525a587406723a1779dcdeda1dec

Issue Description:

Given the struct `Product` which is not conformant to `Equatable` or `Hashable`, a comparison between two `Product`s gives the (expected) error message "Binary operator '==' cannot be applied to two 'Product' operands".

However, when doing the same comparison in `Collection.removeAll(where🙂` on an array of `Product`, e.g.:

products.removeAll(where: { return $0 == product })

you get: "Extra argument 'where' in call"

Removing the `where` argument, e.g.:

products.removeAll({ return $0 == product })

you get: "Missing argument label 'where:' in call"

Converting the closure to trailing closure syntax, e.g.:

products.removeAll { return $0 == product }

you get: "Cannot convert value of type '(_OptionalNilComparisonType) -> Bool' to expected argument type 'Bool'"

@stephentyrone
Copy link
Member

@xedin seems like this might be relatively low-hanging fruit for improvement.

@xedin
Copy link
Member

xedin commented Aug 23, 2019

Thanks for reporting, we are currently in process of trying to port argument-to-parameter conversion failures like this to the new diagnostic framework which should help with this too. Here is a reduced example for posterity:

struct Product {}

func foo(_ products: inout [Product], _ product: Product) {
  products.removeAll(where: { return $0 == product })
}

@xedin
Copy link
Member

xedin commented Dec 4, 2019

@idrougge Looks like this has been improved on master, could you please use next available nightly build of master branch to verify and resolve?

My reduced example now produces:

error: binary operator '==' cannot be applied to two 'Product' operands
    products.removeAll(where: { return $0 == product })
                                       ~~ ^  ~~~~~~~

@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
Projects
None yet
Development

No branches or pull requests

3 participants