Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilquist committed Jan 25, 2022
1 parent 2b4e867 commit dfaf8a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion library/src/scala/deriving/Mirror.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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`. */
Expand Down
21 changes: 5 additions & 16 deletions tests/neg/deriving.scala
Original file line number Diff line number Diff line change
@@ -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() = {
Expand All @@ -9,28 +9,17 @@ 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() = {
case class H() extends F
}
}

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

0 comments on commit dfaf8a4

Please sign in to comment.