scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Typer regression in `zio/zio-schema`

Open WojciechMazur opened this issue 5 days ago • 0 comments

Based on the OpenCB failure in zio/zio-schema - build logs

Compiler version

Last good release: 3.8.0-RC1-bin-20251103-714f3b6-NIGHTLY First bad release: 3.8.0-RC1-bin-20251104-b83b3d9-NIGHTLY

Bisect points to one of: f3aea49b6f7754ffa79beab007fcdac4a37dc4c5 5b03dca156e523a20ca232d9c03dc8d53dd4588e Both are commits from #24231

Not present in 3.8.0-RCs, merged after 3.8.0 cutoff, but before change of build developed version

Minimized code

trait Schema[A]
object Schema:
    final case class Either[A, B](left: Schema[A], right: Schema[B]) extends Schema[scala.util.Either[A, B]]
trait DecodeError

object DynamicValue:
  final case class LeftValue(value: DynamicValue) extends DynamicValue
  final case class RightValue(value: DynamicValue) extends DynamicValue


sealed trait DynamicValue: 
  self =>
    def toTypedValueLazyError[A](using schema: Schema[A]): Either[DecodeError, A] =
      (self, schema) match 
        case (DynamicValue.LeftValue(value), Schema.Either(schema1, _)) =>
          value.toTypedValueLazyError(using schema1).map(Left(_))
        case (DynamicValue.RightValue(value), Schema.Either(_, schema1)) =>
          value.toTypedValueLazyError(using schema1).map(Right(_))
        case _ => ???

Output

Compiling project (Scala 3.8.1-RC1-bin-20251207-68396ca-NIGHTLY, JVM (21))
[error] ./test.scala:16:58
[error] Found:    Left[A, B]
[error] Required: A²
[error] 
[error] where:    A  is a type variable with constraint >: (_$1 : A$1)
[error]           A² is a type in method toTypedValueLazyError which is an alias of Either[A$1, B$1]
[error]           B  is a type variable
[error]           value.toTypedValueLazyError(using schema1).map(Left(_))
[error]                                                          ^^^^^^^
[error] ./test.scala:18:58
[error] Found:    Right[A, B]
[error] Required: A²
[error] 
[error] where:    A  is a type variable
[error]           A² is a type in method toTypedValueLazyError which is an alias of Either[A$2, B$2]
[error]           B  is a type variable with constraint >: (_$2 : B$2)
[error]           value.toTypedValueLazyError(using schema1).map(Right(_))
[error]                                                          ^^^^^^^^

Expectation

Should compile

WojciechMazur avatar Dec 07 '25 16:12 WojciechMazur