Skip to content

Commit

Permalink
Merge pull request #1249 from pomadchin/fix/generic-2.3.8
Browse files Browse the repository at this point in the history
Fix Generic materialization for type aliases (series/2.3)
  • Loading branch information
joroKr21 authored Mar 20, 2022
2 parents 0a08460 + a0abf78 commit 93c1c77
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 @@ -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")

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 @@ -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)))
}

0 comments on commit 93c1c77

Please # to comment.