Bug 14649 – ICE on invalid array operation with string literals
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-06-04T01:42:00Z
Last change time
2015-06-17T21:05:44Z
Keywords
ice, pull
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2015-06-04T01:42:08Z
I found this issue during a check for D2 behavior of issue 1511.
With D2 compiler (2.067 or HEAD:a74d774), adding two char arrays makes "invalid array operation".
void test1()
{
char[] a, b;
string x, y;
auto c = a + b;
// Error: invalid array operation a + b (possible missing [])
auto z = x + y;
// Error: invalid array operation x + y (possible missing [])
}
And if you apply slice operator, they'll make array operations intentionally.
void test2()
{
char[] a = "abc".dup;
char[] b = [char(1), char(2), char(3)];
char[] r = new char[](3);
string x = "abc";
string y = [char(1), char(2), char(3)];
r[] = a[] + b[];
assert(r == "bdf");
r[] = x[] + y[];
assert(r == "bdf");
}
However, using string literals as the operands will cause ICE.
void test3()
{
char[] r = new char[](3);
//r[] = "hel" + "lo.";
// Error: invalid array operation x + y (possible missing [])
// --> expected
r[] = "hel"[] + "lo."[];
// --> Assertion failure (...) on line 1909 in file 'e2ir.c', with HEAD
enum s = "abc";
r[] = s[0..3] + "def"[0..3];
// --> Assertion failure (...) on line 1909 in file 'e2ir.c', with HEAD
}