Thread overview
[Issue 6399] New: [CTFE] struct member array.length -= x doesn't work, while array[0..$-x] works
Jul 29, 2011
Dmitry Olshansky
Jul 30, 2011
Don
Jul 31, 2011
Walter Bright
July 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6399

           Summary: [CTFE] struct member array.length -= x doesn't work,
                    while array[0..$-x] works
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dmitry.olsh@gmail.com


--- Comment #0 from Dmitry Olshansky <dmitry.olsh@gmail.com> 2011-07-29 07:05:49 PDT ---
It has something to do with structs, test case:

struct A{
    int[] arr;
    int subLen()
    {
        arr = [1,2,3, 4,5];
        arr.length -= 1; //replace this line with a next and it compiles
//        arr = arr[0..$-1];
        return arr.length;
    }
}


int getMeFour()
{
    A a;
    return a.subLen();
}

int getMeFour2()
{
    auto arr = [1,2,3, 4,5];
    arr.length -= 1;
    return arr.length;
}

enum t1 = getMeFour();
enum t2 = getMeFour2();//this works regardless of -=x or [0..$-x]
static assert(t1 == 4);
static assert(t2 == 4);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 30, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6399


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2011-07-30 14:03:03 PDT ---
Actually  array.length = array.length - x  also works. It's only +=, -= that fail.

It's because it gets changed into:
(tmp = &array, *(tmp).length = *(tmp.length)-x );
and  (*p).length = n; isn't yet implemented.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 31, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6399


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-07-31 12:10:06 PDT ---
https://github.com/D-Programming-Language/dmd/commit/7ef3b2bb9e740df39108957ae5e3b2aa8253d351

https://github.com/D-Programming-Language/dmd/pull/284

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------