On 10/25/2013 11:45 AM, Jonathan Crapuchettes wrote:
Shouldn't this code work? Looking at the arithmetic conversions section
of http://dlang.org/type.html, point 4.1 makes me think that I shouldn't
be getting the error since they are the same type.
void main()
{
ushort v1 = 1;
ushort v2 = 1;
ushort v3 = v1 + v2;
}
test.d(5): Error: cannot implicitly convert expression (cast(int)v1 + cast
(int)v2) of type int to ushort
But there is 4.0 before 4.1: :)
4. Else the integer promotions are done on each operand, followed by:
1. If both are the same type, no more conversions are done.
Note "integer promotions are done on each operand". In other words, e.g.
there is no arithmetic operation on a ushort. The expression v1 + v2 is
performed as two ints.
Ali