You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could you add sealed keyword to Violation trait for the sake of type-safety of client code?
Compiler warns that match-case statement is not safe on code like:
[error] /...[snip].../AccordExtensions.scala:19: match may not be exhaustive.
[error] It would fail on the following input: List((x: com.wix.accord.Violation forSome x not in (com.wix.accord.GroupViolation, com.wix.accord.RuleViolation)))
[error] treeViolations match {
[error] ^
So client code has to have default case, even if it is unnecessary like:
treeViolations match {
caseNil=> flatViolations
case (violation: RuleViolation) :: violations =>
flattenViolations(violations, flatViolations :+ violation)
case (violation: GroupViolation) :: violations =>
flattenViolations(violation.children.toList ++ violations, flatViolations)
case _ =>thrownewRuntimeException("Invalid state") // Unnecessary case if `Violation` class were sealed.
}
The text was updated successfully, but these errors were encountered:
Not a bad idea, though it's worth noting that one of the reasons it's not yet the case is because the result model is still WIP (obvious case that isn't covered is #21, and there may be ramifications following #36). That being said, changes are going to breaking anyway, so your suggestion still seems appropriate.
I'm a little concerned that this may break client code extending Violation, but since I can't imagine anyone actually doing that I'm going ahead with this. If anyone has feedback to the contrary, I'd love to discuss your use-case.
Could you add
sealed
keyword toViolation
trait for the sake of type-safety of client code?Compiler warns that match-case statement is not safe on code like:
So client code has to have default case, even if it is unnecessary like:
The text was updated successfully, but these errors were encountered: