Bug 2938 – incorrect code generated for assignment to assoc array element

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-05-04T23:31:00Z
Last change time
2015-06-09T01:26:27Z
Assigned to
nobody
Creator
cristian

Comments

Comment #0 by cristian — 2009-05-04T23:31:49Z
This code causes a range violation exception. It goes away if the postblit operator is commented away. The root cause is in the front-end which generates code that gets the element at key zero (to create a temp as argument to opAssign). I was able to work around it in my back-end for .NET, but then the assertion fails, because the front-end does not generate the call to postblit. struct X { int i; this(this) { ++i; } } void main() { X [int] xs; xs[0] = X(); assert(xs[0].i == 1); }
Comment #1 by dsimcha — 2010-01-14T08:34:07Z
Also happens when opAssign is overloaded: struct Foo { uint stuff; void opAssign(Foo rhs) { stuff = rhs.stuff; } } void main() { Foo[string] AA; AA["bar"] = Foo.init; // Range violation. }
Comment #2 by clugdbug — 2010-06-14T01:32:05Z
*** This issue has been marked as a duplicate of issue 2451 ***