On Sun, 22 Feb 2015 02:27:29 +0000, Peter Alexander wrote: > On Sunday, 22 February 2015 at 01:24:09 UTC, Almighty Bob wrote: >> a += b; // Compiles with no ERROR! >> >> Please tell me that's a bug? > > Not a bug. From spec: > > http://dlang.org/expression.html#AssignExpression >> Assignment operator expressions, such as: >> >> a op= b >> >> are semantically equivalent to: >> >> a = cast(typeof(a))(a op b) > > Seems questionable to me. Anyone know the rationale? If a = b; is > disallowed, I don't see why a += b; should be more acceptable.
it's fuuuuuunny!
struct A {
int v = 40;
this (int n) { v = n; }
int opOpAssign(string op) (A b) { return v+b.v; }
}
void main () {
auto a = A();
a += (cast(A)5);
// import std.stdio; writeln(a.v); // can you guess the output?
}
'cmon, guess it without executing the code! but don't ask me why this
psychodelic code can be compiled at all.
signature.asc
Description: PGP signature
