[CODE]
void main()
{
const float[] a;
float[] b;
b[] = b[] + a[]; //works fine
b[] += a[]; //compile error
}
[/CODE]
Compiler output (non conformant errors by the way, file,lines missing):
Error: 'c1' is not a scalar, it is a const(float)[]
Error: incompatible types for ((c1) += (p0[p])): 'const(float)[]' and 'const(float)'
Error: 'c1' is not of arithmetic type, it is a const(float)[]
Comment #1 by clugdbug — 2009-06-08T16:23:23Z
This might as well be an ICE, since the error messages refer to internally generated code, and have no line number.
Applies to all binary arithmetic and logical array operations.
Root cause: cast.c, When e2 is const, and e1 is mutable, typeMerge() transforms
e1 OP= e2 into (cast(const)(e1)) OP= e2.
That's appropriate for +, but not for +=. We only need to check that the operation is legal, no cast should be performed.
PATCH: cast.c, typeMerge(), around line 1532:
else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2))
{
+ // Don't actually convert if it's an array operation
+ if (e->op == TOKaddass || e->op == TOKminass
+ || e->op == TOKmulass || e->op == TOKdivass
+ || e->op == TOKandass ||e->op == TOKorass || e->op == TOKxorass) goto Lret;
goto Lt2;
}