www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1899] New: AA of fixed-length arrays fails to initialize

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1899

           Summary: AA of fixed-length arrays fails to initialize
           Product: D
           Version: 2.012
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: ddparnell bigpond.com


The following code fails with an ArrayBoundsError on the assignment.

void main() 
{
    int[3][string] AA;
    AA["abc"] = [5,4,3];
}

But this code does not fail ...

void main() 
{
    struct S { int[3] v; }
    S[string] AA;
    AA["abc"] = S([5,4,3]);
}


-- 
Mar 08 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1899


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha yahoo.com



*** Issue 4343 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 13 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1899


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |clugdbug yahoo.com.au



PATCH: AssignExp::semantic(). We mustn't convert it into a slice assignment,
because it may be a construction.
Also require an implicit conversion, so that we can allow assignment of array
literals. Quick test case:

void bug1899() 
{
    int[3][string] AA;
    int[3] x = [5,4,3];
    AA["abc"] = x;
    assert(AA["abc"] == x);
    AA["def"] = [1,2,3];
    assert(AA["def"]==[1,2,3]);
}

---
Index: expression.c
===================================================================
--- expression.c    (revision 882)
+++ expression.c    (working copy)
   -9086,10 +9086,23   
     }

     if (t1->ty == Tsarray && !refinit)
-    {   // Convert e1 to e1[]
+    {   
+        if (e1->op == TOKindex &&
+            ((IndexExp *)e1)->e1->type->toBasetype()->ty == Taarray)
+            {
+                // Assignment to an AA of fixed-length arrays.
+                // Convert T[n][U] = T[] into T[n][U] = T[n]
+                e2 = e2->implicitCastTo(sc, e1->type);
+                if (e2->type == Type::terror)
+                    return e2;
+            }
+        else
+        {
+        // Convert e1 to e1[]
         Expression *e = new SliceExp(e1->loc, e1, NULL, NULL);
         e1 = e->semantic(sc);
         t1 = e1->type->toBasetype();
+        }
     }

     e2->rvalue();
   -9131,8 +9144,13   
     else if (t1->ty == Tsarray)
     {
         /* Should have already converted e1 => e1[]
+         * unless it is an AA
          */
-        assert(op == TOKconstruct);
+        if (!(e1->op == TOKindex && t2->ty == Tsarray &&
+            ((IndexExp *)e1)->e1->type->toBasetype()->ty == Taarray))
+        {
+            assert(op == TOKconstruct);
+        }
         //error("cannot assign to static array %s", e1->toChars());
     }
     else if (e1->op == TOKslice)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 19 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1899


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chatelet.guillaume gmail.co
                   |                            |m



*** Issue 5292 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 23 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1899


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



Fixed
https://github.com/D-Programming-Language/dmd/commit/fce5be52f1a7b7e4f910d8bc4ee2b632f6fc9843

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