Thread overview
[Issue 6286] New: Static arrays can not be assigned from const(T)[N] to T[N]
Jul 11, 2011
Sönke Ludwig
Jul 11, 2011
Jonathan M Davis
Jul 11, 2011
Sönke Ludwig
[Issue 6286] Regression(2.054): Static arrays can not be assigned from const(T)[N] to T[N]
Jul 11, 2011
yebblies
Jul 11, 2011
Jonathan M Davis
Aug 05, 2011
Walter Bright
July 11, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6286

           Summary: Static arrays can not be assigned from const(T)[N] to
                    T[N]
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: ludwig@informatik.uni-luebeck.de


--- Comment #0 from Sönke Ludwig <ludwig@informatik.uni-luebeck.de> 2011-07-11 01:52:55 PDT ---
The following snipped worked up to DMD 2.053 but fails on 2.054:

---
void test()
{
    const(int)[4] src = [1, 2, 3, 4];
    int[4] dst;
    dst = src; // Error: cannot implicitly convert expression (src) of type
const(int[4u]) to int[]
    dst[] = src[]; // still works
}
---

The assignment "T[N] = const(T)[N]" should work as long as "T = const(T)" works
as there is no aliasing goind on but just a plain copy.

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


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-07-11 02:05:28 PDT ---
I don't think that this is a bug but rather than dmd used to be buggy with regards to this case.

dst = src;

is assigning src to dst. And assigning a dynamic array to a static one isn't legal. If

dst = src;

were allowed, then it would be inconsistent with the case where both dst and src are dynamic arrays.

dst[] = src[];

on the other hand is specifically copying the elements of src to the elements of dst. So, it's possible that this is a regression and that

dst = src;

is supposed to just translate to

dst[] = src[];

when dst is a static array, but I think that it's far more likely that this is a case where a long-standing bug was fixed.

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



--- Comment #2 from Sönke Ludwig <ludwig@informatik.uni-luebeck.de> 2011-07-11 04:09:49 PDT ---
Note that in the test case both, the source and the destination are static arrays of the same size. There is no reason why a direct assignment should not work here. I think the compiler mistakes the left side here as a dynamic array.

In the case of really assigning a dynamic array to a static one, the decision is definitely not so obvious as it could lead to a hidden runtime error.

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


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, rejects-valid
                 CC|                            |yebblies@gmail.com
            Summary|Static arrays can not be    |Regression(2.054): Static
                   |assigned from const(T)[N]   |arrays can not be assigned
                   |to T[N]                     |from const(T)[N] to T[N]


--- Comment #3 from yebblies <yebblies@gmail.com> 2011-07-12 00:50:34 EST ---
I fear this one was my fault!

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

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



--- Comment #4 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-07-11 08:48:22 PDT ---
Ah yes. I didn't read carefully enough. If both src and dst are static arrays, then

dst = src;

should work. It's when one is a dynamic array that it shouldn't.

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


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2011-08-05 12:34:48 PDT ---
https://github.com/D-Programming-Language/dmd/commit/d29588f3410b85625559c6af5118fce484fd05af

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