wix-incubator / accord

Accord: A sane validation library for Scala
http://wix.github.io/accord/
Other
529 stars 55 forks source link

Problem with basic validator example #124

Open buildreactive opened 6 years ago

buildreactive commented 6 years ago

I'm trying to set up a validator based on the web site example. I've got:

import com.wix.accord.dsl._

case class Deck (
    id: Option[UUID],
    number: Int,
    name: String,
    code: String,
    isPax: Boolean,
) {
    def safeId = id.getOrElse(UUID.randomUUID())
}

object Deck {
    val LOWEST = 3
    val HIGHEST = 20

    /**
      * A validator defines all the business logic for validating attributes. Validators can be called at any time with
      * the `validate()` function. Typically `validate()` is called right after creating a new instance.
      */
    implicit val deckValidator = validator[Deck] { p =>
        p.code.length is between(1, 4) // The expression being validated is resolved automatically, see below
        p.code should matchRegex(".*")
    }
}

Which generates the following errors:

[error] /Users/zbeckman/Projects/Lightbend/NCL/zero-ship-service/ship-api/src/main/scala/com/ncl/zero/api/ship/Deck.scala:28:47: exception during macro expansion:
[error] java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.tl$1()Lscala/collection/immutable/List;
[error]         at com.wix.accord.transform.FunctionDescriber$class.describeFunction(ExpressionDescriber.scala:145)
[error]         at com.wix.accord.transform.ValidationTransform.describeFunction(ValidationTransform.scala:24)
[error]         at com.wix.accord.transform.ValidationTransform.<init>(ValidationTransform.scala:36)
[error]         at com.wix.accord.transform.ValidationTransform$.apply(ValidationTransform.scala:240)
[error]         implicit val deckValidator = validator[Deck] { p =>
[error]                                                      ^
holograph commented 6 years ago

That's odd. Guess the move to tut (or similar) is more deserved than I thought. I'll look into it, thanks for reporting!

holograph commented 6 years ago

As with #123, I've failed to reproduce this on any Scala version. Can you specify which versions of Accord, Scala and JDK you're using?

holograph commented 6 years ago

(also pinging @noam-almog to sort out the administrativa)

holograph commented 6 years ago

Perhaps you are compiling with Scala 2.12.5 with JDK 9/10? It has a known regression with macros: https://github.com/scala/scala/releases/tag/v2.12.5