Associative Array of Const Objects?
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Mar 28 02:30:00 PDT 2015
On Friday, 27 March 2015 at 21:33:19 UTC, bitwise wrote:
> class Test{}
>
> void main()
> {
> const(Test)[string] tests;
> tests["test"] = new Test();
> }
>
> This code used to work, but after upgrading to dmd 2.067, it no
> longer does.
> --Error: cannot modify const expression tests["test"]
>
> How do I insert an item into an associative array of const
> objects?
FWIW, it was changed in
https://github.com/D-Programming-Language/dmd/pull/4148
It seems Kenji argues that the first assignment (like in your
case) should be allowed, because it's supposed to be a
construction rather than an assignment, but I fail to see how the
compiler could detect this in the general case.
More information about the Digitalmars-d-learn
mailing list