From f172995e574a7109af018b86df31e33f041b3656 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Fri, 20 Mar 2020 18:03:33 +0100 Subject: [PATCH 1/2] Add missing asInstanceOf call --- core/src/main/scala/shapeless/generic.scala | 2 +- .../shapeless/LabelledGenericTests213.scala | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 core/src/test/scala_2.13+/shapeless/LabelledGenericTests213.scala diff --git a/core/src/main/scala/shapeless/generic.scala b/core/src/main/scala/shapeless/generic.scala index 8fee7c6aa..6f27a3861 100644 --- a/core/src/main/scala/shapeless/generic.scala +++ b/core/src/main/scala/shapeless/generic.scala @@ -1025,7 +1025,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_2.13+/shapeless/LabelledGenericTests213.scala b/core/src/test/scala_2.13+/shapeless/LabelledGenericTests213.scala new file mode 100644 index 000000000..7fbe26965 --- /dev/null +++ b/core/src/test/scala_2.13+/shapeless/LabelledGenericTests213.scala @@ -0,0 +1,22 @@ +package shapeless + +import org.junit.Assert._ +import org.junit.Test +import shapeless.ops.record.Selector + +class LabelledGenericTests213 { + import LabelledGenericTests213._ + + @Test + def testSelectorWithHkt(): Unit = { + assertEquals(0, new Func[Hkt[Option]].select("foo")) + assertEquals(0, new Func[Hkt[Id]].select("foo")) + } +} + +object LabelledGenericTests213 { + 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 + } +} From 8755d92fe8d8da0bb88547ec3c5dbe055f15d952 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Sat, 24 Apr 2021 14:51:30 +0200 Subject: [PATCH 2/2] Back to Symbol --- .../test/scala_2.13+/shapeless/LabelledGenericTests213.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/scala_2.13+/shapeless/LabelledGenericTests213.scala b/core/src/test/scala_2.13+/shapeless/LabelledGenericTests213.scala index 7fbe26965..4bc204df6 100644 --- a/core/src/test/scala_2.13+/shapeless/LabelledGenericTests213.scala +++ b/core/src/test/scala_2.13+/shapeless/LabelledGenericTests213.scala @@ -9,8 +9,8 @@ class LabelledGenericTests213 { @Test def testSelectorWithHkt(): Unit = { - assertEquals(0, new Func[Hkt[Option]].select("foo")) - assertEquals(0, new Func[Hkt[Id]].select("foo")) + assertEquals(0, new Func[Hkt[Option]].select(Symbol("foo"))) + assertEquals(0, new Func[Hkt[Id]].select(Symbol("foo"))) } }