Skip to content

Commit

Permalink
Add missing asInstanceOf call
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 committed Mar 24, 2020
1 parent 88a803f commit 393496f
Show file tree
Hide file tree
Showing 2 changed files with 12 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 @@ -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 })"
}

Expand Down
11 changes: 11 additions & 0 deletions core/src/test/scala/shapeless/labelledgeneric.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")))
}
}

0 comments on commit 393496f

Please # to comment.