Бесформенный, не находящий следов в тесте, но может в REPL
У меня есть case-класс, который выглядит так:
case class Color(name: String, red: Int, green: Int, blue: Int)
Я использую Shapeless 2.3.1 с Scala 2.11.8. Я вижу другое поведение по сравнению с моим тестом и REPL с точки зрения нахождения неявного значения дляLabelledGeneric[Color]
, (Я на самом деле пытаюсь автоматически получить некоторый другой класс типов, но я получаюnull
за это тоже)
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
}
}
}
Этот тест не проходит, потому чтоcolorLabel
являетсяnull
, Зачем?
Из REPL я могу найти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