D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2938 - incorrect code generated for assignment to assoc array element
Summary: incorrect code generated for assignment to assoc array element
Status: RESOLVED DUPLICATE of issue 2451
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-04 23:31 UTC by Cristi Vlasceanu
Modified: 2015-06-09 01:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Cristi Vlasceanu 2009-05-04 23:31:49 UTC
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 David Simcha 2010-01-14 08:34:07 UTC
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 Don 2010-06-14 01:32:05 UTC

*** This issue has been marked as a duplicate of issue 2451 ***