RFC: Value range propagation for if-else

Lionello Lunesu via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 18 09:14:50 PDT 2014


On 18/06/14 16:28, bearophile wrote:
> Lionello Lunesu:
>
>>> ubyte foo(immutable int x)
>>> in {
>>>     assert(x >= 0 && x <= ubyte.max);
>>> } body {
>>>     return x;
>>> }
>>
>> Yeah, I wanted to support "assert" as well, but it doesn't create a
>> scope so it'll be a bit trickier to implement.
>
> If you have an assert in a pre-condition and the argument is const, then
> the body{} is the scope you look for.
>
> Bye,
> bearophile

That's a good point! I checked the DMD code and it seems doable. I can 
reuse the "ConditionVisitor" that I wrote for if-else.

Will play with it.


More information about the Digitalmars-d mailing list