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
Given the following sealed trait, it is possible to see that at runtime there is the possibility of a MatchError being thrown -
sealedtraitExprfinalcaseclassFoo(other: Option[String]) extendsExprfinalcaseclassBar(someConstant: String) extendsExprfinalcaseclassBaz() extendsExprfinalcaseclassEatsExhaustiveWarning(other: Reference) extendsExprsealedtraitReference {
valvalue:String
}
objectReference {
defunapply(reference: Reference):Option[(String)] = {
Some(reference.value)
}
}
objectEntryPoint {
defmain(args: Array[String]) {
println("Successfully ran")
}
privatedeflogic(head: Expr):String= head match {
caseFoo(_) =>???// Commenting this line only causes the exhaustive search warning to be emittedcaseEatsExhaustiveWarning(Reference(text)) =>???
}
}
From the scala docs
If the selector of a pattern match is an instance of a sealed class (s5.2), the compilation of pattern matching can emit warnings which diagnose that a given set of patterns is not exhaustive, i.e. that there is a possibility of a MatchError being raised at run-time.
It seems that when the unapply method is provided for the Reference trait, no compiler warnings are emitted.
The text was updated successfully, but these errors were encountered:
Given the following sealed trait, it is possible to see that at runtime there is the possibility of a MatchError being thrown -
From the scala docs
It seems that when the unapply method is provided for the Reference trait, no compiler warnings are emitted.
The text was updated successfully, but these errors were encountered: