diff --git a/core/src/main/scala/shapeless/generic.scala b/core/src/main/scala/shapeless/generic.scala index 3d8abf976..e37b264a2 100644 --- a/core/src/main/scala/shapeless/generic.scala +++ b/core/src/main/scala/shapeless/generic.scala @@ -1011,7 +1011,7 @@ class GenericMacros(val c: whitebox.Context) extends CaseClassMacros { val (p, ts) = ctorDtor.binding val to = cq"$p => ${mkHListValue(ts)}.asInstanceOf[$repr]" val (rp, rts) = ctorDtor.reprBinding - val from = cq"$rp => ${ctorDtor.construct(rts)}" + val from = cq"$rp => ${ctorDtor.construct(rts)}.asInstanceOf[$tpe]" q"$generic.instance[$tpe, $repr]({ case $to }, { case $from })" } diff --git a/core/src/test/scala/shapeless/labelledgeneric.scala b/core/src/test/scala/shapeless/labelledgeneric.scala index 1fd293e78..2d1dfc613 100644 --- a/core/src/test/scala/shapeless/labelledgeneric.scala +++ b/core/src/test/scala/shapeless/labelledgeneric.scala @@ -36,6 +36,11 @@ object LabelledGenericTestsAux { case class Private3(a: Int, private val b: String) case class Private4(private val a: Int, b: String) + case class Hkt[F[_]](foo: F[String]) + class Func[T] { + def select[R <: HList](k: Witness)(implicit gen: LabelledGeneric.Aux[T, R], selector: Selector[R, k.T]) = 0 + } + val tapl = Book("Benjamin Pierce", "Types and Programming Languages", 262162091, 44.11) val tapl2 = Book("Benjamin Pierce", "Types and Programming Languages (2nd Ed.)", 262162091, 46.11) val taplExt = ExtendedBook("Benjamin Pierce", "Types and Programming Languages", 262162091, 44.11, true) @@ -462,4 +467,10 @@ class LabelledGenericTests { implicitly[lgent.Repr =:= RT] implicitly[TC[RT]] } + + @Test + def testSelectorWithHktOfId: Unit = { + assertEquals(0, new Func[Hkt[Option]].select(Symbol("foo"))) + assertEquals(0, new Func[Hkt[Id]].select(Symbol("foo"))) + } }