[Issue 14649] New: ICE on invalid array operation with string literals

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 3 18:42:08 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14649

          Issue ID: 14649
           Summary: ICE on invalid array operation with string literals
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ice
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: k.hara.pg at gmail.com

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
}

--


More information about the Digitalmars-d-bugs mailing list