RFC: Value range propagation for if-else
Lionello Lunesu via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 19 18:54:50 PDT 2014
On 19/06/14 15:59, Timon Gehr wrote:
> 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
> }
That will only work now if you use an "else".
More information about the Digitalmars-d
mailing list