- 
                Notifications
    
You must be signed in to change notification settings  - Fork 33
 
Description
I've run into a very strange error with ScalaSQL 0.1.20, Scala 3.7.2 and ZIO 2.1.20.
The code looks as follows:
import scalasql.PostgresDialect.*
import scalasql.simple.{*}
import scalasql.*
case class Test(
  id: Long,
)
sealed trait Task[+A]
def attemptBlocking[A](block: A): Task[A] = ???
object Test extends SimpleTable[Test]
def persist(db: DbClient): Task[Unit] =
  attemptBlocking:
    db.transaction: tx =>
      val importId = 0L
      tx.run:
        Test.insert.batched(
        _.id,
        )(
          Seq(importId)*
        )https://scastie.scala-lang.org/G70bLQMwTpaRXYRGNeKGng
It yields the following error:
No given instance of type scalasql.core.Queryable[
  scalasql.query.InsertColumns[
    [T[_$2]] =>> scalasql.namedtuples.SimpleTable.MapOver[Playground.Test, T],
    Playground.Test],
R] was found for parameter qr of method run in trait DbApi.
I found:
    scalasql.core.Expr.ExprQueryable[E, T²]
But method ExprQueryable in object Expr does not match type scalasql.core.Queryable[
  scalasql.query.InsertColumns[
    [T[_$2]] =>> scalasql.namedtuples.SimpleTable.MapOver[Playground.Test, T],
    Playground.Test],
R]
where:    R  is a type variable with constraint <: Unit
          T  is a type variable with constraint <: [_] =>> Any
          T² is a type variable
.
Note: a match type could not be fully reduced:
  trying to reduce  scalasql.namedtuples.SimpleTable.MapOver[Playground.Test, T]
  failed since selector T[scalasql.namedtuples.SimpleTable.Internal.Tombstone.type]
  does not match  case scalasql.namedtuples.SimpleTable.Internal.Tombstone.type => Playground.Test
  and cannot be shown to be disjoint from it either.
  Therefore, reduction cannot advance to the remaining case
    case Any => scalasql.namedtuples.SimpleTable.Record[Playground.Test, T]
It has something to do with the attemptBlocking line and with value-discard. A version without attemptBlocking compiles fine:
https://scastie.scala-lang.org/57yQAWWiROO4eiWteOag7A
As does a version with an explicit () to avoid discarding the Int value returned by tx.run:
https://scastie.scala-lang.org/o52Wxo91SyCyF0nNueXMMA
Interestingly, the same code in Scala 3.6.4 causes a compiler crash.
https://scastie.scala-lang.org/nFgtr2uhSzGgQ7WoAciNQQ
This might mean that there was a crashing bug in 3.6.4 that was then "fixed" in a way that prevents the crash but still doesn't do the right thing.