diff --git a/library/src/scala/deriving/Mirror.scala b/library/src/scala/deriving/Mirror.scala index 5cbb423fc2c8..d091f4ee559e 100644 --- a/library/src/scala/deriving/Mirror.scala +++ b/library/src/scala/deriving/Mirror.scala @@ -53,7 +53,7 @@ object Mirror { extension [T](p: ProductOf[T]) /** Create a new instance of type `T` with elements taken from product `a`. */ @annotation.experimental - def fromProductTyped[A <: scala.Product](a: A)(using m: ProductOf[A], ev: p.MirroredElemTypes =:= m.MirroredElemTypes): T = + def fromProductTyped[A <: scala.Product, Elems <: p.MirroredElemTypes](a: A)(using m: ProductOf[A] { type MirroredElemTypes = Elems }): T = p.fromProduct(a) /** Create a new instance of type `T` with elements taken from tuple `t`. */ diff --git a/tests/neg/deriving.scala b/tests/neg/deriving.scala index d2ade97c1544..4d8d0f001cec 100644 --- a/tests/neg/deriving.scala +++ b/tests/neg/deriving.scala @@ -1,6 +1,6 @@ -import deriving.MirrorOf +import reflect.Generic -sealed trait A +sealed trait A derives Generic // error: cannot take shape, it has anonymous or inaccessible subclasses object A { def f() = { @@ -9,19 +9,13 @@ object A { } } -def aMirror = summon[Mirror.Of[A]] // error: cannot take shape, it has anonymous or inaccessible subclasses - -sealed trait B +sealed trait B derives Generic // error: cannot take shape, its subclass class D is not a case class class D(x: Int, y: String) extends B -def bMirror = summon[Mirror.Of[B]] // error: cannot take shape, its subclass class D is not a case class - -class E -def eMirror = summon[Mirror.Of[E]] // error: cannot take shape, it is neither sealed nor a case class +class E derives Generic // error: cannot take shape, it is neither sealed nor a case class -sealed trait F -def fMirror = summon[Mirror.Of[F]] // error: cannot take shape, it has anonymous or inaccessible subclasses +sealed trait F derives Generic // error: cannot take shape, it has anonymous or inaccessible subclasses object G { def f() = { @@ -29,8 +23,3 @@ object G { } } -case class I(x: Int, y: String) -object I: - def f = summon[deriving.Mirror.ProductOf[I]].fromProductTyped((1, 2)) // error - def g = summon[deriving.Mirror.ProductOf[I]].fromTuple((1, 2)) // error -