I have a case class that looks like this:
case class Color(name: String, red: Int, green: Int, blue: Int)
I am using Shapeless 2.3.1 with Scala 2.11.8. I see different behavior from my test and REPL in terms of finding an implicit value for LabelledGeneric[Color] . (I'm actually trying to automatically output some other classes, but I get null too)
Internal test
package foo import shapeless._ import org.specs2.mutable._ case class Color(name: String, red: Int, green: Int, blue: Int) object CustomProtocol { implicit val colorLabel: LabelledGeneric[Color] = LabelledGeneric[Color] } class GenericFormatsSpec extends Specification { val color = Color("CadetBlue", 95, 158, 160) "The case class example" should { "behave as expected" in { import CustomProtocol._ assert(colorLabel != null, "colorLabel is null") 1 mustEqual 1 } } }
This test failed because colorLabel is null . Why?
REPL
From REPL, I can find LabelledGeneric[Color] :
scala> case class Color(name: String, red: Int, green: Int, blue: Int) defined class Color scala> import shapeless._ import shapeless._ scala> LabelledGeneric[Color] res0: shapeless.LabelledGeneric[Color]{type Repr = shapeless.::[String with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("name")],String],shapeless.::[Int with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("red")],Int],shapeless.::[Int with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("green")],Int],shapeless.::[Int with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("blue")],Int],shapeless.HNil]]]]} = shapeless.LabelledGeneric$$anon$1@755f11d9
source share