On Sunday, 22 February 2015 at 01:32:16 UTC, Adam D. Ruppe wrote:
On Sunday, 22 February 2015 at 01:24:09 UTC, Almighty Bob wrote:
Please tell me that's a bug?

Nope, a is clearly an int in the last case so no conversion is needed.

a is an int in all three cases, b is a float in all three cases.

In one case the compiler automatically converts b to an int before adding it to a. In the other two cases it gives an error. So..

a=a+b;
a+=b;

Are not the same, OK, it seems odd that a "shorthand" version of an expression would have slightly different semantics than the longhand version but fundamentally what bothers me is any automatic conversion from float to int. It should never be automatic.

Ok I looked up the docs, and they say...

http://dlang.org/expression.html

"Assign Expressions:
The right operand is implicitly converted to the type of the left operand"

which quite clearly is not the case since...

a=b; // causes an error. but..
a+=b; // does not.

Reply via email to