From ef6f1513d426b167680c7fbf2cb33dea0b8deb55 Mon Sep 17 00:00:00 2001 From: Grigory Pomadchin Date: Sat, 19 Mar 2022 20:17:34 -0400 Subject: [PATCH] Fix Generic materialization for type aliases --- core/src/main/scala/shapeless/generic.scala | 2 +- core/src/test/scala/shapeless/generic.scala | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/shapeless/generic.scala b/core/src/main/scala/shapeless/generic.scala index 36a6cc64e..77a0768e0 100644 --- a/core/src/main/scala/shapeless/generic.scala +++ b/core/src/main/scala/shapeless/generic.scala @@ -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") diff --git a/core/src/test/scala/shapeless/generic.scala b/core/src/test/scala/shapeless/generic.scala index c1c2112ed..a750d9cf1 100644 --- a/core/src/test/scala/shapeless/generic.scala +++ b/core/src/test/scala/shapeless/generic.scala @@ -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))) +}