Skip to content

Commit 6eee60b

Browse files
committed
Statement shouldn't inherit from Hashable
We made `Statement: Hashable` for convenience in holding onto statements in a shared key for SQLiteData, but that isn't really necessary, since we can always call out to the underlying query fragment to get a hashable value. This conformance unfortunately can cause bugs, including `==` resolving to the equality operator when a query operator was expected. Another bug is that `@Table @Selection` types conform to `Statement`, and this equatable implementation was preferred over the default synthesized version, making `Table` values equatable strictly by the underlying query, which meant `@Ephemeral` fields weren't taken into account at all. With 0.20.0, all `@Table` applications introduced a `Statement` conformance, and so this issue becomes much more widespread. While this change can break SQLiteData if someone upgrades StructuredQueries before upgrading SQLiteData with the changes from pointfreeco/sqlite-data#245.
1 parent dcf489f commit 6eee60b

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// A type that represents a full SQL query.
2-
public protocol Statement<QueryValue>: QueryExpression, Hashable {
2+
public protocol Statement<QueryValue>: QueryExpression {
33
/// A type representing the table being queried.
44
associatedtype From: Table
55

@@ -15,13 +15,3 @@ extension Statement {
1515
"(\(.newline)\(query.indented())\(.newline))"
1616
}
1717
}
18-
19-
extension Statement {
20-
public static func == (lhs: Self, rhs: Self) -> Bool {
21-
lhs.query == rhs.query
22-
}
23-
24-
public func hash(into hasher: inout Hasher) {
25-
hasher.combine(query)
26-
}
27-
}

Tests/StructuredQueriesTests/EphemeralTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ extension SnapshotTests {
1717
"""
1818
}
1919
}
20+
21+
@Test func equality() {
22+
#expect(TestTable(displayName: "Blob Jr") != TestTable(displayName: "Blob Sr"))
23+
}
2024
}
2125
}
2226

0 commit comments

Comments
 (0)