Skip to content

Commit

Permalink
Merge pull request #1250 from pomadchin/fix/generic
Browse files Browse the repository at this point in the history
Fix Generic materialization for type aliases
  • Loading branch information
joroKr21 authored Mar 20, 2022
2 parents 3634e62 + ef6f151 commit d8516ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/scala/shapeless/generic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ class GenericMacros(val c: whitebox.Context) extends CaseClassMacros {
def materialize[T: WeakTypeTag, R]: Tree = mkGeneric[T]

def mkGeneric[T: WeakTypeTag]: Tree = {
val tpe = weakTypeOf[T]
val tpe = weakTypeOf[T].dealias
if (isReprType(tpe))
abort("No Generic instance available for HList or Coproduct")

Expand Down
16 changes: 16 additions & 0 deletions core/src/test/scala/shapeless/generic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1371,3 +1371,19 @@ object CaseClassWithImplicits {
def shouldCompile[T: ATypeClass]
: Generic.Aux[ACaseClassWithContextBound[T], HNil] = Generic[ACaseClassWithContextBound[T]]
}

object AliasMaterialization {
// https://github.com/milessabin/shapeless/issues/1248
case class TX2[A, B](a: A, b: B)
case class TX3[A, B, C](a: A, b: B, c: C)

def shouldCompile1[A, B](data: TX2[A, B])(implicit g: Generic[TX2[A, B]]): Unit = {}

shouldCompile1(TX2[Int, Boolean](1, true))

type TTX3[A, B] = TX3[Long, Int, TX2[A, B]]

def shouldCompile2[A, B](data: TTX3[A, B])(implicit g: Generic[TTX3[A, B]]): Unit = {}

shouldCompile2(TX3(1L, 1, TX2(1, true)))
}

0 comments on commit d8516ce

Please # to comment.