Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in yurikpanic/zio-postgres - ambigious extension methods prevent type reduction #20288

Closed
WojciechMazur opened this issue Apr 29, 2024 · 2 comments · Fixed by #20857
Assignees
Labels
Milestone

Comments

@WojciechMazur
Copy link
Contributor

Based on OpenCB failure in yurikpanic/zio-postgres - build logs

Compiler version

Last good release: 3.5.0-RC1-bin-20240406-521ce95-NIGHTLY
First bad release: 3.5.0-RC1-bin-20240408-1e8a653-NIGHTLY

Failed to finish bisect - the compiler fails to compile, first bad commit can by any of 389f5be 1dc5b99

Minimized code

trait Decoder[A]
object Decoder {
  given Decoder[DataRow] = ???
  extension [A <: Tuple](d: Decoder[A])
    def ~[B](fd: Field[B]): Decoder[Tuple.Concat[A, Tuple1[B]]] = ???
}

trait Field[A]
object Field:
  val int: Field[Int] = ???
  extension [A](self: Field[A])
    def ~[B](that: Field[B])(using Decoder[DataRow]): Decoder[(A, B)] = ???

trait DataRow
def simpleQuery[S, A](query: String)(using Decoder[A]): Either[Throwable, A] = ???

@main def Test = {
  import Decoder.*
  val fails = simpleQuery("")(using
    Field.int ~ Field.int ~ Field.int
  )
}

Output

-- [E007] Type Mismatch Error: /Users/wmazur/projects/dotty/bisect/sandbox.scala:20:4 
20 |    Field.int ~ Field.int ~ Field.int
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |    Found:    Decoder[(Int, Int, Int)]
   |    Required: Decoder[Tuple.Concat[(Int, Int), Tuple1[Int]]]
   |
   | longer explanation available when compiling with `-explain`

Expectation

The result type should be fully reduced into tuple.

@WojciechMazur
Copy link
Contributor Author

Seems like another project fails due to 389f5be - I've not managed to minimize the compilation error in katrix/perspective (build logs), but I've run the project-base bisect - it points to mentioned commit. This project is a heavy user of inlines, also "abstract" inlines provided by the class implementors in the extensions, and is really difficult to make it work without dependencies in manageable amount of source code.

@WojciechMazur
Copy link
Contributor Author

One more affected project alterationx10/opinionated-zio it's bisect points to the same commits. This time we don't have ambigious extension methods, yet, still type reduction fails

// 1_defns.scala
import scala.compiletime.*
import scala.deriving.*

sealed trait ZIO[-R, +E, +A]
sealed abstract class ZLayer[-RIn, +E, +ROut]
object ZLayer:
    def apply[RIn, E, ROut](zio: => ZIO[RIn, E, ROut]): ZLayer[RIn, E, ROut] = ???
type URIO[-R, +A] = ZIO[R, Nothing, A]
type IAnyType[T <: Tuple] = Tuple.Fold[T, Any, [x, y] =>> x & y]
type UAnyType[T <: Tuple] = Tuple.Fold[T, Any, [x, y] =>> x | y]


trait AutoLayer[A]:
  def zlayer(using
      p: Mirror.ProductOf[A]
  ): ZLayer[IAnyType[p.MirroredElemTypes], Nothing, A]

object AutoLayer:
  inline given derived[A](using p: Mirror.ProductOf[A]): AutoLayer[A] = {
    val a: ZIO[IAnyType[p.MirroredElemTypes], Nothing, A] = ???
    new AutoLayer[A]:
      override def zlayer(using
          pp: Mirror.ProductOf[A]
      ): ZLayer[IAnyType[pp.MirroredElemTypes], Nothing, A] = ZLayer {
        a.asInstanceOf[ZIO[IAnyType[pp.MirroredElemTypes], Nothing, A]]
      }
    }
// 2_usage.scala
case class TestService(port: Int) derives AutoLayer

yields:

[error] Found:    ZLayer[Tuple.Fold[pp.MirroredElemTypes, Any, [x, y] =>> x & y], Nothing,
[error]   TestService]
[error] Required: ZLayer[IAnyType[pp.MirroredElemTypes], Nothing, TestService]
[error] 
[error] Note: a match type could not be fully reduced:
[error] 
[error]   trying to reduce  Tuple.Fold[pp.MirroredElemTypes, Any, [x, y] =>> x & y]
[error]   failed since selector pp.MirroredElemTypes
[error]   does not match  case EmptyTuple => Any
[error]   and cannot be shown to be disjoint from it either.
[error]   Therefore, reduction cannot advance to the remaining case
[error] 
[error]     case h *: t => h & Tuple.Fold[t, Any, [x, y] =>> x & y]
[error] case class TestService(port: Int) derives AutoLayer

EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Jun 28, 2024
@Kordyjan Kordyjan added this to the 3.5.1 milestone Jul 3, 2024
WojciechMazur pushed a commit that referenced this issue Jul 8, 2024
WojciechMazur added a commit that referenced this issue Jul 9, 2024
)

Backports #20857 to the LTS branch.

PR submitted by the release tooling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants