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 alterationx10/opinionated-zio match types #20858

Closed
EugeneFlesselle opened this issue Jun 28, 2024 · 2 comments · Fixed by #21017
Closed

Regression in alterationx10/opinionated-zio match types #20858

EugeneFlesselle opened this issue Jun 28, 2024 · 2 comments · Fixed by #21017
Assignees
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore

Comments

@EugeneFlesselle
Copy link
Contributor

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

Originally posted by @WojciechMazur in #20288 (comment)

@EugeneFlesselle
Copy link
Contributor Author

Related to #18261

@Gedochao Gedochao added itype:bug area:typer regression This worked in a previous version but doesn't anymore labels Jul 3, 2024
@EugeneFlesselle
Copy link
Contributor Author

Minimization:

type M[F[_, _]] = Int match
  case 0 => String & M[F]

type A = M[[x,y] =>> x & y]

def Test: Unit =
  val x: A = ???
  val _: M[[x,y] =>> x & y] = x // error

WojciechMazur pushed a commit that referenced this issue Aug 28, 2024
…21017)

Before the changes, when comparing two `HKTypeLambda` result types, the
list of binding pairs was lost when entering comparison of `AndOrType`s,
which caused the `equals` to fail, and hence prevented hash-consing.

Even though `M1` and `M2` in pos/i20858-min should still conform to
one-another, we entered a deep-subtype comparison because of the order
in which the TypeComparer does dealiasing of AppliedTypes, and
comparison of MatchCases and AndTypes.

Fix #20858
[Cherry-picked f2829c3]
prolativ pushed a commit that referenced this issue Nov 20, 2024
…21017)

Before the changes, when comparing two `HKTypeLambda` result types, the
list of binding pairs was lost when entering comparison of `AndOrType`s,
which caused the `equals` to fail, and hence prevented hash-consing.

Even though `M1` and `M2` in pos/i20858-min should still conform to
one-another, we entered a deep-subtype comparison because of the order
in which the TypeComparer does dealiasing of AppliedTypes, and
comparison of MatchCases and AndTypes.

Fix #20858
[Cherry-picked f2829c3]
prolativ pushed a commit that referenced this issue Nov 21, 2024
…21017)

Before the changes, when comparing two `HKTypeLambda` result types, the
list of binding pairs was lost when entering comparison of `AndOrType`s,
which caused the `equals` to fail, and hence prevented hash-consing.

Even though `M1` and `M2` in pos/i20858-min should still conform to
one-another, we entered a deep-subtype comparison because of the order
in which the TypeComparer does dealiasing of AppliedTypes, and
comparison of MatchCases and AndTypes.

Fix #20858
[Cherry-picked f2829c3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants