File tree Expand file tree Collapse file tree 2 files changed +6
-17
lines changed
library/src/scala/deriving Expand file tree Collapse file tree 2 files changed +6
-17
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ object Mirror {
53
53
extension [T ](p : ProductOf [T ])
54
54
/** Create a new instance of type `T` with elements taken from product `a`. */
55
55
@ 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 =
57
57
p.fromProduct(a)
58
58
59
59
/** Create a new instance of type `T` with elements taken from tuple `t`. */
Original file line number Diff line number Diff line change 1
- import deriving . MirrorOf
1
+ import reflect . Generic
2
2
3
- sealed trait A
3
+ sealed trait A derives Generic // error: cannot take shape, it has anonymous or inaccessible subclasses
4
4
5
5
object A {
6
6
def f () = {
@@ -9,28 +9,17 @@ object A {
9
9
}
10
10
}
11
11
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
15
13
16
14
class D (x : Int , y : String ) extends B
17
15
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
22
17
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
25
19
26
20
object G {
27
21
def f () = {
28
22
case class H () extends F
29
23
}
30
24
}
31
25
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
-
You can’t perform that action at this time.
0 commit comments