wix-incubator / accord

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

Multiple multiple validation rules in control structures is incorrect #141

Closed CatTail closed 5 years ago

CatTail commented 5 years ago

When using multiple is false validation rules inside control structure, it seems only the last rule matters, below is an example to reproduce the issue.

object AccordConditionIssueApp extends App {

  case class Something(bool1: Boolean, bool2: Boolean, bool3: Boolean)

  val condition = true

  implicit val somethingValidator = validator[Something] { o =>
    if (condition) {
      o.bool1 is false
      o.bool2 is false
    }

    o.bool3 is false
  }

  // Following example expected to be invalid, but it turned out to be valid
  val invalidSomething = Something(bool1 = true, bool2 = false, bool3 = false)
  println(validate(invalidSomething)) // => Success
}

https://github.com/CatTail/scala-playground/blob/77b265529afab42e1cbd28beb296b3a67b3cf343/src/main/scala/com/example/playground/AccordApp.scala#L32-L50

holograph commented 5 years ago

Confirmed. Looking into it

holograph commented 5 years ago

PR issued. @noam-almog ball's in your court :-)