Skip to content

Commit

Permalink
fix: EXPOSED-366 inList with EntityID column causes type mismatch err…
Browse files Browse the repository at this point in the history
…or (#2070)

Since 0.50.0, attempting to use an iterable of comparables with inList() invoked
by an EntityID column leads to a type mismatch.
This happens because the incorrect overload is being resolved, following a generics
type parameter move.

The same issue applies for notInList() and reverting the change allows valid iterables
to be used and wrapped by the correct overload.
  • Loading branch information
bog-walk authored May 2, 2024
1 parent f424216 commit 8ab6697
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ interface ISqlExpressionBuilder {
/** Checks if this expression is equals to any element from [list]. */
@Suppress("UNCHECKED_CAST")
@JvmName("inListIds")
infix fun <T : Comparable<T>> Column<EntityID<T>?>.inList(list: Iterable<T>): InListOrNotInListBaseOp<EntityID<T>?> {
infix fun <T : Comparable<T>, ID : EntityID<T>?> Column<ID>.inList(list: Iterable<T>): InListOrNotInListBaseOp<EntityID<T>?> {
val idTable = (columnType as EntityIDColumnType<T>).idColumn.table as IdTable<T>
return SingleValueInListOp(this, list.map { EntityIDFunctionProvider.createEntityID(it, idTable) }, isInList = true)
}
Expand Down Expand Up @@ -863,7 +863,7 @@ interface ISqlExpressionBuilder {
/** Checks if this expression is not equals to any element from [list]. */
@Suppress("UNCHECKED_CAST")
@JvmName("notInListIds")
infix fun <T : Comparable<T>> Column<EntityID<T>?>.notInList(list: Iterable<T>): InListOrNotInListBaseOp<EntityID<T>?> {
infix fun <T : Comparable<T>, ID : EntityID<T>?> Column<ID>.notInList(list: Iterable<T>): InListOrNotInListBaseOp<EntityID<T>?> {
val idTable = (columnType as EntityIDColumnType<T>).idColumn.table as IdTable<T>
return SingleValueInListOp(this, list.map { EntityIDFunctionProvider.createEntityID(it, idTable) }, isInList = false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,20 @@ class SelectTests : DatabaseTestsBase() {
category = EntityTests.Category.new { title = "Category1" }
}

val result = EntityTests.Posts.selectAll().where {
val result1 = EntityTests.Posts.selectAll().where {
EntityTests.Posts.board inList listOf(board1.id)
}.singleOrNull()?.get(EntityTests.Posts.id)
assertEquals(post1.id, result)
assertEquals(post1.id, result1)

val result2 = EntityTests.Board.find {
EntityTests.Boards.id inList listOf(1, 2, 3, 4, 5)
}.singleOrNull()
assertEquals(board1, result2)

val result3 = EntityTests.Board.find {
EntityTests.Boards.id notInList listOf(1, 2, 3, 4, 5)
}.singleOrNull()
assertNull(result3)
}
}

Expand Down

0 comments on commit 8ab6697

Please sign in to comment.