Bug 2277 – array ops and const arrays incompatible

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-08-10T06:01:00Z
Last change time
2015-06-09T01:20:08Z
Keywords
diagnostic, ice-on-valid-code, patch, rejects-valid
Assigned to
bugzilla
Creator
spam

Comments

Comment #0 by spam — 2008-08-10T06:01:58Z
[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; }
Comment #2 by bugzilla — 2009-09-03T13:33:55Z
Fixed dmd 2.032