Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix Generic materialization for type aliases #1250

Merged
merged 1 commit into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))
}