For discussion: Compile-time Errors
Here’s a very preliminary PR — not ready for primetime yet, but looking for discussion and terribly interesting. It adds the ability to define flexible, intuitive, compile-time, type-level errors, like this:
type RequirePositive[T <: Int] <: Any = (T >= 0) match {
case true => Any
case false => Error["The provided value (" + ToString[T] + ") isn't positive"]
}
It needs refinement still (and it’s not certain that it will even turn out to work), but it is oh-so-very cool, and it makes sense: now that Scala is gaining better machinery for doing type-level computations at compile time, we need corresponding ways to express the problem when those computations go wrong.
If nothing else, it’s worthwhile to look at as an example of the new thinking around type-level programming in Dotty, which is one of the more exciting aspects coming in Scala 3.
If you’re interested in power Scala I recommend giving it a look…