SQLite.swift icon indicating copy to clipboard operation
SQLite.swift copied to clipboard

Cannot invoke 'filter' with an argument list of type '(Bool)'

Open krzyzanowskim opened this issue 10 years ago • 6 comments

I have this:

keywords.filter(!SQLite.contains(foundKeywords,  Expression<String>("Word"))

and Swift 1.2 report: Error: Cannot invoke 'filter' with an argument list of type '(Bool)' but only when compiled with -O (release)

I want to build "NOT IN" clause. What I'm doing wrong?

krzyzanowskim avatar Jul 29 '15 22:07 krzyzanowskim

@krzyzanowskim Huh. That looks right. I'm assuming there's a compiler bug in Swift 1.2, but hopefully we can find a workaround. What if you move the filter above?

let keywordFilter = !SQLite.contains(foundKeywords,  Expression<String>("Word")
keywords.filter(keywordFilter)

stephencelis avatar Jul 30 '15 13:07 stephencelis

that did not help, I had to workaround usage of "!" function. Since wrap() is private, I did this:

let containsExpression = SQLite.contains(foundKeywords, DBKeywords.Word)
let notContainsExpression:Expression<Bool> = Expression(literal: "NOT (\(containsExpression.SQL))", containsExpression.bindings)

krzyzanowskim avatar Jul 30 '15 13:07 krzyzanowskim

That should be an OK workaround for now. I'll see if I can find a better one. This is likely fixed in 2.0, though.

stephencelis avatar Jul 30 '15 14:07 stephencelis

I am facing this issue even on swift 2.1.1

       do {
            let row = placesTable.filter( placeID == 1)

            if try app.sharedInstance.database.run(row.delete()) > 0 {
                print("row deleted")
            } else {
                print("row not found")
            }
        } catch {
            print("delete failed: \(error)")
        }

This line shows a compile error let row = placesTable.filter( placeID == 1)

Cannot invoke 'filter' with an argument list of type '(Bool)'

bijugv avatar Feb 16 '16 07:02 bijugv

I came across exactly the same problem as bijugv using xCode 10.1, swift 4.2. The line:

let query = clients.where(clientKey == 1)

Generates the error message Cannot invoke 'filter' with an argument list of type '(Bool)'.

Which was very puzzling as similar code in other parts of the app worked fine.

It appears to be something weird with the compiler. After a frustrating hour or so I created another function with the exact same code and all was well!

ByronJJ avatar Dec 02 '18 09:12 ByronJJ

Looks like this was caused by some Swift compatibility change?

jberkel avatar Aug 25 '21 10:08 jberkel