RFC: Value range propagation for if-else

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 19 00:59:12 PDT 2014


On 06/18/2014 09:54 PM, Meta wrote:
> ...
>
> This could be a bad thing. It makes it pretty enticing to use contracts
> as input verification instead of logic verification.

The following is doable as well with a standard range analysis:

byte foo(immutable int x){
     if(x<byte.min || x>byte.max)
         throw new InvalidArgumentException("...");
     return x; // ok
}


More information about the Digitalmars-d mailing list