From a0abf78a027872248c4dd5bbbc0f951dbf4510bc Mon Sep 17 00:00:00 2001 From: Grigory Pomadchin Date: Sat, 19 Mar 2022 20:09:49 -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 a222b0839..1ff52b300 100644 --- a/core/src/main/scala/shapeless/generic.scala +++ b/core/src/main/scala/shapeless/generic.scala @@ -1052,7 +1052,7 @@ class GenericMacros(val c: whitebox.Context) extends CaseClassMacros { private val generic = objectRef[Generic.type] def materialize[T: WeakTypeTag, R: 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 cffc8525f..518610134 100644 --- a/core/src/test/scala/shapeless/generic.scala +++ b/core/src/test/scala/shapeless/generic.scala @@ -1367,3 +1367,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))) +}