[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
https://issues.dlang.org/show_bug.cgi?id=2451 Andrei Alexandrescu and...@erdani.com changed: What|Removed |Added Version|2.020 |D2 --
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
http://d.puremagic.com/issues/show_bug.cgi?id=2451 Walter Bright bugzi...@digitalmars.com changed: What|Removed |Added Status|NEW |RESOLVED CC||bugzi...@digitalmars.com Resolution||FIXED --- Comment #11 from Walter Bright bugzi...@digitalmars.com 2010-10-20 00:16:30 PDT --- http://www.dsource.org/projects/dmd/changeset/723 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
http://d.puremagic.com/issues/show_bug.cgi?id=2451 Don clugd...@yahoo.com.au changed: What|Removed |Added Keywords||patch --- Comment #9 from Don clugd...@yahoo.com.au 2010-10-19 15:07:26 PDT --- Here's a patch. Do the opAssign onto a temporary variable, then blit the temporary into the AA as normal. TEST CASE: struct Foo { int z = 3; void opAssign(Foo x) { z= 2;} } struct Foo2 { int z = 3; this(this){ z = 17; } } void main() { Foo[string] stuff; stuff[foo] = Foo.init; assert(stuff[foo].z == 2); Foo2[string] stuff2; Foo2 q; stuff2[dog] = q; assert(stuff2[dog].z == 17); } PATCH: expression.c line 8966, AssignExp::semantic. - /* If it is an assignment from a 'foreign' type, * check for operator overloading. */ if (t1-ty == Tstruct) { StructDeclaration *sd = ((TypeStruct *)t1)-sym; if (op == TOKassign) { 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); +Identifier *id = Lexer::uniqueId(__aatmp); +VarDeclaration *v = new VarDeclaration(loc, e2-type, +id, new VoidInitializer(NULL)); +v-storage_class |= STCctfe; +Expression *de = new DeclarationExp(loc, v); +VarExp *ve = new VarExp(loc, v); +AssignExp *ae = new AssignExp(loc, ve, e2); +e = ae-op_overload(sc); +e2 = new CommaExp(loc, new CommaExp(loc, de, e), ve); +e2 = e2-semantic(sc); +} +else if (e) return e; -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
http://d.puremagic.com/issues/show_bug.cgi?id=2451 Don clugd...@yahoo.com.au changed: What|Removed |Added CC||lud...@informatik.uni-luebe ||ck.de --- Comment #10 from Don clugd...@yahoo.com.au 2010-10-19 15:13:39 PDT --- *** Issue 1886 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: ---
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
http://d.puremagic.com/issues/show_bug.cgi?id=2451 --- Comment #8 from Don clugd...@yahoo.com.au 2010-08-19 07:23:47 PDT --- Bug 3705 (Can't add structs with alias this to an AA) is probably related. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
http://d.puremagic.com/issues/show_bug.cgi?id=2451 Don clugd...@yahoo.com.au changed: What|Removed |Added Status|ASSIGNED|NEW -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
http://d.puremagic.com/issues/show_bug.cgi?id=2451 Don clugd...@yahoo.com.au changed: What|Removed |Added CC||crist...@zerobugs.org --- Comment #6 from Don clugd...@yahoo.com.au 2010-06-14 01:32:05 PDT --- *** Issue 2938 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: ---
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
http://d.puremagic.com/issues/show_bug.cgi?id=2451 Don clugd...@yahoo.com.au changed: What|Removed |Added CC||bearophile_h...@eml.cc --- Comment #7 from Don clugd...@yahoo.com.au 2010-06-14 06:46:04 PDT --- *** Issue 4121 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: ---
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
http://d.puremagic.com/issues/show_bug.cgi?id=2451 --- Comment #5 from Don clugd...@yahoo.com.au 2010-05-22 07:15:10 PDT --- I don't have a patch for this, but the direct reason for the observed behaviour is in expression.c, line 9023. If the type being inserted has an opAssign overload, then it drops out of AssignExp::semantic() immediately and discards the rest of the expression. This isn't a real patch, since it still doesn't call postblit. /* If it is an assignment from a 'foreign' type, * check for operator overloading. */ if (t1-ty == Tstruct) { StructDeclaration *sd = ((TypeStruct *)t1)-sym; if (op == TOKassign) { Expression *e = op_overload(sc); +if (e1-op==TOKindex +((IndexExp *)e1)-e1-type-toBasetype()-ty == Taarray) +{ +// If it is an AA, the assignment +// should be treated as a function call (Bugzilla 2451) +} +else if (e) return e; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 2451] Adding structs that use opAssign or postblit to an AA is broken
http://d.puremagic.com/issues/show_bug.cgi?id=2451 GG ggcod...@gmail.com changed: What|Removed |Added CC||ggcod...@gmail.com --- Comment #4 from GG ggcod...@gmail.com 2010-02-15 12:14:09 PST --- import std.variant; Variant[char[]][int] aa; aa[0][a] = bla0; aa[0][b] = 100; aa[1][a] = bla1; aa[1][b] = 200; With 32-bit Linux and dmd2.039 or dmd2.040 Compile : success Running : core.exception.rangeer...@test(30): Range violation -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---