On 21/08/16 12:47, ag0aep6g wrote:
On 08/21/2016 07:12 AM, Shachar Shemesh wrote:
During static analysis, keep both the "most expanded" and the "least
expanded" type of the expression parsed so far. "Least expanded" is the
largest type actually used in the expression.
What's "most expanded"?
As expanded as we plan on making it. In our current semantics, "int" or
"uint".
Upon use of the value, resolve which type to actually use for it. If the
use type requests a type between least and most, use that type for
evaluating the entire expression. If the use requests a type outside
that range, use the one closest (and, if the use is below the range,
complain about narrowing conversion).
So when only ubytes are involved, all calculations would be done on
ubytes, no promotions, right? There are cases where that would give
different results than doing promotions.
Consider `ubyte(255) * ubyte(2) / ubyte(2)`. If the operands are
promoted to a larger type, you get 255 as the result. If they are not,
you have the equivalent of `ubyte x = 255; x *= 2; x /= 2;` which gives
you 127.
You are right. This is a hole in this suggestion. Let me think if it is
plugable.
Shachar