Sem forma não encontrar implícitos no teste, mas pode no REPL
Eu tenho uma classe de caso que se parece com isso:
case class Color(name: String, red: Int, green: Int, blue: Int)
Estou usando Shapeless 2.3.1 com Scala 2.11.8. Estou vendo um comportamento diferente do meu teste e do REPL em termos de encontrar o valor implícito paraLabelledGeneric[Color]
. (Na verdade, estou tentando derivar automaticamente outras classes, mas estou recebendonull
por isso também)
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
}
}
}
Este teste falha porquecolorLabel
énull
. Por quê?
No REPL, posso encontrarLabelledGeneric[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