Mirrors and variance

So this works:

trait Foo[A]

object Foo:
  given [A <: Product](using m: Mirror.ProductOf[A]): Foo[A] = ???

def foo =
  summon[Foo[(String, Int)]]

However, when the trait is made contra- (or co-) variant:

trait Bar[-A]

object Bar:
  given [A <: Product](using m: Mirror.ProductOf[A]): Bar[A] = ???

def bar =
  summon[Bar[(String, Int)]]

it fails with Failed to synthesize an instance of type deriving.Mirror.ProductOf[A]: trait Product is not a generic product because it is not a case class. on the last line.

First, the error message doesn’t make sense to me at all. I’m also not able to wrap my head around whether the variance should matter here.

Any chance this could be a compiler bug?

1 Like

For the record: the issue that caused this is fixed in 3.2.1-RC1.

3 Likes