Parameter Packs: Generic parameter 'each Value' could not be inferred

I have a function like:

protocol SQLValueConvertible {
    static func value(statement: OpaquePointer, index: Int32) -> Any
}

extension String: SQLValueConvertible {
    public static func value(statement: OpaquePointer, index: Int32) -> Any {
        sqlite3_column_text(statement, index).map({ String(cString: $0) }) ?? ""
    }
}

protocol SQLiteTable {
    associatedtype StatementColumns
}

func query<Table: SQLiteTable, Value1: SQLValueConvertible, Value2: SQLValueConvertible>(table: Table) -> [Table.StatementColumns] where Table.StatementColumns == (Value1, Value2) { }

When I call this function

struct QueryTable: SQLiteTable {
    typealias StatementColumns = (value1: String, value2: String)
}
query(table: QueryTable())

It gives me these errors:

Generic parameter 'Value1' could not be inferred
Generic parameter 'Value2' could not be inferred
Instance method 'query(table:)' requires the types 'QueryTable.StatementColumns' (aka '(value1: String, value2: String)') and '(Value1, Value2)' be equivalent

Is this a limitation of swift? Or am I using it wrong?

There's your answer. One is a labelled tuple and the other is an unlabelled tuple, so they aren't technically the same type.

1 Like

So it is the limitation of Swift. Thanks!

I also tried the Parameter Packs

func query<Table: SQLiteTable, each Value: SQLValueConvertible>(table: Table) async -> [Table.StatementColumns] where Table.StatementColumns == (repeat each Value) {

And it give me this error:

Generic parameter 'each Value' could not be inferred
Instance method 'query(table:)' requires the types 'QueryTable.StatementColumns' (aka '(value1: String, value2: String)') and '(repeat each Value)' be equivalent

Looks like the same limitation