www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5131] New: [ICE] opAssign and associative arrays (AA) are broken for types != this

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

           Summary: [ICE] opAssign and associative arrays (AA) are broken
                    for types != this
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: sandford jhu.edu



Using DMD 2.050, when trying to assign a value to an associative array that is
not the type of the AA results in an ICE.

Here are two test cases:

import std.variant;
void main() {
    Variant[string] a;
    a["ICE?"] = 1;
}

------------------------

struct ICE {
    ICE opAssign(int x) { return this; }
};
void main() {
    ICE[string] a;
    a["ICE?"] = 1;
}

Note that:

void main() {
    Variant[string] a;
    a["ICE?"] = Variant(1);
}

compiles correctly. See http://d.puremagic.com/issues/show_bug.cgi?id=2451

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch



With  val[key] = e2, the temporary variable needs to be of typeof(val), not
typeof(e2).
PATCH:
expression.c, AssignExp::semantic(), line 8974.

            Expression *e = op_overload(sc);
            if (e && e1->op == TOKindex &&
                ((IndexExp *)e1)->e1->type->toBasetype()->ty == Taarray)
            {
                // Deal with AAs (Bugzilla 2451)
                // Rewrite as:
-                // e1 = (typeof(e2) tmp = void, tmp = e2, tmp);
+                // e1 = (typeof(aa.value) tmp = void, tmp = e2, tmp);
+                Type * aaValueType = ((TypeAArray *)((IndexExp
*)e1)->e1->type->toBasetype())->next;
                Identifier *id = Lexer::uniqueId("__aatmp");
-                VarDeclaration *v = new VarDeclaration(loc, e2->type,
                    id, new VoidInitializer(NULL));
+                VarDeclaration *v = new VarDeclaration(loc, aaValueType,
                    id, new VoidInitializer(NULL));
                v->storage_class |= STCctfe;

                Expression *de = new DeclarationExp(loc, v);
                VarExp *ve = new VarExp(loc, v);

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


Walter Bright <bugzilla digitalmars.com> changed:

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



17:46:04 PST ---
http://www.dsource.org/projects/dmd/changeset/743

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