Skip to content

Commit e700581

Browse files
committed
Address review comments
1 parent 136fafc commit e700581

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

library/src/scala/deriving/Mirror.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ object Mirror {
5353
extension [T](p: ProductOf[T])
5454
/** Create a new instance of type `T` with elements taken from product `a`. */
5555
@annotation.experimental
56-
def fromProductTyped[A <: scala.Product](a: A)(using m: ProductOf[A], ev: p.MirroredElemTypes =:= m.MirroredElemTypes): T =
56+
def fromProductTyped[A <: scala.Product, Elems <: p.MirroredElemTypes](a: A)(using m: ProductOf[A] { type MirroredElemTypes = Elems }): T =
5757
p.fromProduct(a)
5858

5959
/** Create a new instance of type `T` with elements taken from tuple `t`. */

tests/neg/deriving.scala

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import deriving.MirrorOf
1+
import reflect.Generic
22

3-
sealed trait A
3+
sealed trait A derives Generic // error: cannot take shape, it has anonymous or inaccessible subclasses
44

55
object A {
66
def f() = {
@@ -9,28 +9,17 @@ object A {
99
}
1010
}
1111

12-
def aMirror = summon[Mirror.Of[A]] // error: cannot take shape, it has anonymous or inaccessible subclasses
13-
14-
sealed trait B
12+
sealed trait B derives Generic // error: cannot take shape, its subclass class D is not a case class
1513

1614
class D(x: Int, y: String) extends B
1715

18-
def bMirror = summon[Mirror.Of[B]] // error: cannot take shape, its subclass class D is not a case class
19-
20-
class E
21-
def eMirror = summon[Mirror.Of[E]] // error: cannot take shape, it is neither sealed nor a case class
16+
class E derives Generic // error: cannot take shape, it is neither sealed nor a case class
2217

23-
sealed trait F
24-
def fMirror = summon[Mirror.Of[F]] // error: cannot take shape, it has anonymous or inaccessible subclasses
18+
sealed trait F derives Generic // error: cannot take shape, it has anonymous or inaccessible subclasses
2519

2620
object G {
2721
def f() = {
2822
case class H() extends F
2923
}
3024
}
3125

32-
case class I(x: Int, y: String)
33-
object I:
34-
def f = summon[deriving.Mirror.ProductOf[I]].fromProductTyped((1, 2)) // error
35-
def g = summon[deriving.Mirror.ProductOf[I]].fromTuple((1, 2)) // error
36-

0 commit comments

Comments
 (0)