Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with basic validator example #124

Open
buildreactive opened this issue Jun 7, 2018 · 4 comments
Open

Problem with basic validator example #124

buildreactive opened this issue Jun 7, 2018 · 4 comments

Comments

@buildreactive
Copy link

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

@holograph
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants