micvos
I must agree with Peter. This is not a bug. Altough the assignment operator is right associative the c# grammar is specified from left ot right. This means that the most left assignment operator is evaluated first before the ones to the right. This is a problem which occurs even difficult to compiler builders. For example this problem occurs also for java compilers which uses roughly the same grammar. I have seen a number of java compiler clones which use a different evaluation order than that of the sun compiler. This is also specified in the c# specification altough it's difficcult to read:
7.13.2 Compound assignment
An operation of the form x op= y is processed by applying binary operator overload resolution (ˇě7.2.4) as if the operation was written x op y. Then,
If the return type of the selected operator is implicitly convertible to the type of x, the operation is evaluated as x = x op y, except that x is evaluated only once.
Otherwise, if the selected operator is a predefined operator, if the return type of the selected operator is explicitly convertible to the type of x, and if y is implicitly convertible to the type of x or the operator is a shift operator, then the operation is evaluated as x = (T)(x op y), where T is the type of x, except that x is evaluated only once.
Otherwise, the compound assignment is invalid, and a compile-time error occurs.
The term ˇ°evaluated only onceˇ± means that in the evaluation of x op y, the results of any constituent expressions of x are temporarily saved and then reused when performing the assignment to x. For example, in the assignment A()[B()] += C(), where A is a method returning int[], and B and C are methods returning int, the methods are invoked only once, in the order A, B, C.
Pay attention to the last section in which it says the evaluation order is form left to right and that intermediate values are temporarily saved (which means they are not assigned to the original variable).