Comment #2 by andrej.mitrovich — 2013-05-02T12:33:18Z
I don't understand the bug, what's the issue here?
Comment #3 by lio+bugzilla — 2013-05-02T17:35:02Z
(In reply to comment #2)
> I don't understand the bug, what's the issue here?
Any calculation with 'i' that uses VRP get the full int range, not the constant 1. The same holds for 'const int'.
Comment #4 by lio+bugzilla — 2013-05-02T18:16:16Z
Degrading to P4, since in many cases, calling optimize() on the Expression before doing getIntRange() will in fact return the constant range.
Not closing until I've identified that indeed implementing VarExp::getIntRange() would NOT have any effect.
Comment #5 by bearophile_hugs — 2013-07-10T04:43:10Z
(In reply to comment #1)
> https://github.com/D-Programming-Language/dmd/pull/1955
This is a good improvement for D. I hope you will fix and reopen your patch.
But I think this issue should be tagged as "enhancement".
See also Issue 10594 for an "improvement" of this idea.
Comment #6 by bearophile_hugs — 2013-07-20T13:58:03Z
Se also Issue 10685 , Issue 10615 , Issue 10594
Comment #7 by yebblies — 2013-11-21T08:11:57Z
This seems to work just fine:
void main()
{
immutable int i = 1;
byte x = i;
}
Comment #8 by bearophile_hugs — 2014-03-16T08:49:12Z
The value range of immutable variables is not yet propagated (see Issue 10594 ):
void main(in string[] args) {
immutable ushort x = args.length % 5;
immutable ubyte y = x;
}
DMD 2.066alpha gives:
temp.d(3,25): Error: cannot implicitly convert expression (x) of type immutable(ushort) to immutable(ubyte)
Comment #9 by lio+bugzilla — 2014-06-28T04:40:20Z
(In reply to yebblies from comment #7)
> This seems to work just fine:
>
> void main()
> {
> immutable int i = 1;
> byte x = i;
> }
This works now because a call to optimize() will remove the reference to 'i' and replace it with the constant expression. If it's not a constant expression (for example, ?: not known at compile time) then it won't propagate the range.
Comment #10 by lio+bugzilla — 2014-06-28T04:57:05Z