D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2277 - array ops and const arrays incompatible
Summary: array ops and const arrays incompatible
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: diagnostic, ice-on-valid-code, patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2008-08-10 06:01 UTC by Stephan Dilly
Modified: 2015-06-09 01:20 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Stephan Dilly 2008-08-10 06:01:58 UTC
[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 Don 2009-06-08 16:23:23 UTC
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 Walter Bright 2009-09-03 13:33:55 UTC
Fixed dmd 2.032