I do not believe that you can have common restrictions / statements that are checked at compile time in Scala, because Scala does not have the static verifier that is needed for this. If you're interested, check out (research) languages ββ/ tools such as ESC / Java , SpeC # , Dafny, or VeriFast .
There may be ways with a very limited amount of static checking using a regular Scala compiler using level programming at a level or Scala , but this is just a wild hunch about mine, as I am not familiar with any of them. Honestly, I have to admit that I would be very surprised if macros really help here.
What does run-time validation check work, for example
case class Foo(arg1: Int, arg2: Int) { require(arg1 < arg2, "The first argument must be strictly less than " + "the second argument.") } Foo(0, 0)
but thatβs not what you had in mind.
Malte schwerhoff
source share