You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The cause seems to be the fact that the field 'foo' is a prefix of field foo-foo. E.g. when I rename the 'foo' field to 'foo1' I get the expected output.
import shapeless._
trait Const[A] {
def const(v: A): String
}
object Const {
def apply[A](implicit F: Const[A]): Const[A] = F
def instance[A](g: A => String): Const[A] = v => g(v)
}
trait Consts[A] {
def consts(v: A): List[String]
}
object Consts {
def apply[A](implicit F: Consts[A]): Consts[A] = F
def instance[A](g: A => List[String]): Consts[A] = v => g(v)
implicit val hnil: Consts[HNil] = instance(_ => Nil)
implicit def hlist[H, T <: HList](implicit F: Const[H], G: Consts[T]): Consts[H :: T] =
instance({ case h :: t => F.const(h) +: G.consts(t) })
implicit def generic[A, R](implicit F: Generic.Aux[A, R], G: Consts[R]): Consts[A] =
instance(v => G.consts(F.to(v)))
}
case class Foo(s: String)
object Foo {
implicit val const: Const[Foo] = Const.instance(_.s)
}
case class Bar(`foo-foo`: Foo, foo: Foo)
object Scratch extends App {
println(Consts[Bar].consts(Bar(Foo("abc"), Foo("5"))))
}
The bug does not manifest when you swap the field order.
A smaller example, though that uses scalaz is
import scalaz._, Scalaz._
import shapeless._
trait Consts[A] {
def consts(v: A): List[String]
}
object Consts {
def apply[A](implicit F: Consts[A]): Consts[A] = F
def instance[A](g: A => List[String]): Consts[A] = v => g(v)
implicit val hnil: Consts[HNil] = instance(_ => Nil)
implicit def hlist[H, T <: HList](implicit F: Show[H], G: Consts[T]): Consts[H :: T] =
instance({ case h :: t => F.shows(h) +: G.consts(t) })
implicit def generic[A, R](implicit F: Generic.Aux[A, R], G: Consts[R]): Consts[A] =
instance(v => G.consts(F.to(v)))
}
case class Foo(s: String)
object Foo {
implicit val show: Show[Foo] = Show.shows(_.s)
}
case class Bar(`foo-foo`: Foo, foo: Foo)
object Scratch extends App {
println(Consts[Bar].consts(Bar(Foo("abc"), Foo("5"))))
}
The text was updated successfully, but these errors were encountered:
The following program generates the output
rather than the expected
The cause seems to be the fact that the field 'foo' is a prefix of field
foo-foo
. E.g. when I rename the 'foo' field to 'foo1' I get the expected output.The bug does not manifest when you swap the field order.
A smaller example, though that uses scalaz is
The text was updated successfully, but these errors were encountered: