Let's say, I've got a function increase_balance(increment_value: int) but instead of allowing all possible integer values, I want the compiler to check that anytime this function is called, it is called with increment_value in the range 1 to 10000.
Is it theoretically possible to do such checks at compile-time? I mean the compiler has to check every code path and verify that all code paths leading to increase_balance() leads to value that is neither <= 0 nor >= 10001. Is this is a problem that can be solved at compile-time? Does any programming language provide such features?
While I've your attention, are there other such invariants you're aware of that can be checked during compile-time?
Overall, there's no free lunch: somewhere, someone will have to do some extra work.
Other useful invariants include some RAII idioms, Rust memory checks, resource usage (e.g. locks), etc.
Some languages like F* are also proof oriented.