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 apache/pekko-connectors for derivation #21236

Closed
WojciechMazur opened this issue Jul 19, 2024 · 1 comment
Closed

Regression in apache/pekko-connectors for derivation #21236

WojciechMazur opened this issue Jul 19, 2024 · 1 comment
Labels

Comments

@WojciechMazur
Copy link
Contributor

Based on OpenCB failure for apache/pekko-connectors - build logs

Compiler version

Since 3.4.0
Last good release: 3.4.0-RC1-bin-20231212-97e4401-NIGHTLY
First bad release: 3.4.0-RC1-bin-20231213-9dce045-NIGHTLY
Bisect points to d6c7e18

Minimized code

import scala.deriving.Mirror

type FieldType[K, +V] = (K, V)
type ZipWith[T1 <: Tuple, T2 <: Tuple, F[_, _]] <: Tuple = (T1, T2) match
  case (h1 *: t1, h2 *: t2) => F[h1, h2] *: ZipWith[t1, t2, F]
  case (EmptyTuple, ?)      => EmptyTuple
  case (?, EmptyTuple)      => EmptyTuple
  case _                    => Tuple

trait LabelledGeneric[A]:
  type Repr <: Tuple

object LabelledGeneric:
  type Aux[A, R] = LabelledGeneric[A] { type Repr = R }
  inline given productInst[A <: Product](using m: Mirror.ProductOf[A]): LabelledGeneric.Aux[A, ZipWith[m.MirroredElemLabels, m.MirroredElemTypes, FieldType]] =
    new LabelledGeneric[A]:
      type Repr = ZipWith[m.MirroredElemLabels, m.MirroredElemTypes, FieldType]

trait PdxEncoder[A]
object PdxEncoder:
  given objectEncoder[A, Repr <: Tuple](using LabelledGeneric.Aux[A, Repr]): PdxEncoder[A] = ???

case class Person(id: Int, name: String)

@main def Test =
  val fails: PdxEncoder[Person] = PdxEncoder.objectEncoder // error

Output

-- [E172] Type Error: /Users/wmazur/projects/scala3/bisect/test.scala:27:58 ----
27 |  val fails: PdxEncoder[Person] = PdxEncoder.objectEncoder
   |                                                          ^
   |No given instance of type LabelledGeneric.Aux[Person, Repr] was found for parameter x$1 of given instance objectEncoder in object PdxEncoder.
   |I found:
   |
   |    LabelledGeneric.productInst[Person](
   |      Person.$asInstanceOf[
   |        
   |          scala.deriving.Mirror.Product{
   |            type MirroredMonoType = Person; type MirroredType = Person;
   |              type MirroredLabel = ("Person" : String);
   |              type MirroredElemTypes = (Int, String);
   |              type MirroredElemLabels = (("id" : String), ("name" : String))
   |          }
   |        
   |      ]
   |    )
   |
   |But given instance productInst in object LabelledGeneric does not match type LabelledGeneric.Aux[Person, Repr]
   |
   |where:    Repr is a type variable with constraint <: Tuple
   |.

Expectation

Should probably compile

Workaround

Defining LabelledGeneric.productInst as transparent inline fixes the problem

@WojciechMazur
Copy link
Contributor Author

Closing as it works as expected, the commit mentioned in bisect describes that it's expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant