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/incubator-pekko-connectors #19479

Closed
WojciechMazur opened this issue Jan 18, 2024 · 6 comments · Fixed by #19922
Closed

Regression in apache/incubator-pekko-connectors #19479

WojciechMazur opened this issue Jan 18, 2024 · 6 comments · Fixed by #19922
Assignees
Labels
area:implicits related to implicits area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

Based on OpenCB build failure in apache/incubator-pekko-connectors - build logs

Compiler version

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

Minimized code

case class Person(id: Int)

class GeodeContinuousSourceSpec {
  summon[PdxEncoder[Person]]
}

trait PdxEncoder[A] {
  def encode(a: A): Boolean
}

object PdxEncoder extends ObjectEncoder {
  implicit def intEncoder: PdxEncoder[Int] = ???
}

trait ObjectEncoder {
  given emptyTupleEncoder: PdxEncoder[EmptyTuple] = ???

  given tupleEncoder[K <: String, H, T <: Tuple](using
      m: ValueOf[K],
      hEncoder: PdxEncoder[H],
      tEncoder: PdxEncoder[T]
  ): PdxEncoder[FieldType[K, H] *: T] = ???

  given objectEncoder[A, Repr <: Tuple](using
      gen: LabelledGeneric.Aux[A, Repr],
      tupleEncoder: PdxEncoder[Repr]
  ): PdxEncoder[A] = ???
}

import scala.deriving.Mirror

private type FieldType[K, +V] = V & KeyTag[K, V]
private type KeyTag[K, +V]
private 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
}

private trait LabelledGeneric[A] {
  type Repr
}

private 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 = Tuple & ZipWith[m.MirroredElemLabels, m.MirroredElemTypes, FieldType]
    }
}

Output

-- [E172] Type Error: /Users/wmazur/projects/sandbox/main.scala:4:28 -----------
4 |  summon[PdxEncoder[Person]]
  |                            ^
  |No given instance of type PdxEncoder[Person] was found for parameter x of method summon in object Predef.
  |I found:
  |
  |    PdxEncoder.objectEncoder[Person, Repr](
  |      LabelledGeneric.productInst[Person](
  |        Person.$asInstanceOf[
  |          
  |            scala.deriving.Mirror.Product{
  |              type MirroredMonoType = Person; type MirroredType = Person;
  |                type MirroredLabel = ("Person" : String);
  |                type MirroredElemTypes = Int *: EmptyTuple.type;
  |                type MirroredElemLabels = ("id" : String) *: EmptyTuple.type
  |            }
  |          
  |        ]
  |      ),
  |    ???)
  |
  |But given instance productInst in object LabelledGeneric does not match type LabelledGeneric.Aux[Person, Repr].
1 error found

Expectation

Not sure if it's false negative or not. Needs confirmation it works as expected or to provide a fix.

@WojciechMazur WojciechMazur added itype:bug area:typer area:implicits related to implicits regression This worked in a previous version but doesn't anymore labels Jan 18, 2024
@bishabosha bishabosha assigned sjrd and unassigned bishabosha Jan 19, 2024
@bishabosha
Copy link
Member

bishabosha commented Jan 19, 2024

I don't think this has an issue with mirrors, the ZipWith match type also seems to work, now I'm checking again it was assigned to me because I made the change to add the constrain result fix in #19253

@bishabosha bishabosha assigned dwijnand and unassigned sjrd Jan 19, 2024
@bishabosha
Copy link
Member

bishabosha commented Jan 19, 2024

If you want to fix the compilation, then it compiles if LabelledGeneric.productInst is made transparent inline.

Maybe there's another way of redesigning the code to propagate the types if you want to keep it inline.

@dwijnand
Copy link
Member

Changing what, how and when type vars are constraints can affect match type resolution.

@dwijnand dwijnand assigned bishabosha and unassigned dwijnand Jan 25, 2024
@bishabosha
Copy link
Member

bishabosha commented Apr 4, 2024

I've tested this and it is now working in 3.4.2-RC1, so I guess something else changed to improve the inference, and I think we should add regression test and close

@bishabosha
Copy link
Member

no, actually the whole code was reverted in #19922, so no longer causes this

@bishabosha
Copy link
Member

fixed by #19922

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits 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.

5 participants