Bug 16047 – Range violation in setting multi-dimensional AA entries
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-05-19T15:04:32Z
Last change time
2019-09-24T04:39:44Z
Keywords
pull
Assigned to
No Owner
Creator
Mario Kroeplin
Comments
Comment #0 by kroeplin.d — 2016-05-19T15:04:32Z
The following code results in a range violation for the second assignment to `aa`, while the first assignment to `aa` works as expected:
unittest
{
import std.datetime;
struct S
{
string s;
this(string s)
{
this.s = s;
}
}
SysTime[string][string] aa;
aa["bar"]["bar"] = SysTime.init;
aa[S("baz").s]["baz"] = SysTime.init; // Range violation
}
Any further reduction of the example eliminates the issue.
Comment #1 by kroeplin.d — 2019-09-20T13:18:11Z
Workaround: use `require`
aa.require(S("baz").s, null)["baz"] = SysTime.init;
Comment #2 by default_357-line — 2019-09-20T14:14:38Z
Comment #3 by default_357-line — 2019-09-20T15:27:45Z
What happens here is that the complex expression for the first index forces DMD to allocate a temporary. In the course of doing so, it forgets to indicate that the temporary is for a nested assignment, and the temporary (which is a plain IndexExp, not an assignment) runs into a range error.
Comment #4 by dlang-bot — 2019-09-20T16:05:15Z
@FeepingCreature updated dlang/dmd pull request #10422 "fix issue 16048: range error when assigning nested aa with temporary" fixing this issue:
- fix issue 16047: when extracting temporaries from an index expression for assignment, mark the expression as assigning.
This avoids the temporaries encountering a range error with nested associative arrays.
https://github.com/dlang/dmd/pull/10422
Comment #5 by dlang-bot — 2019-09-24T04:39:44Z
dlang/dmd pull request #10422 "fix issue 16047: range error when assigning nested aa with temporary" was merged into master:
- c3d94591422f5d9366639683c5a0c50f4c48aa64 by Mathis Beer:
fix issue 16047: when extracting temporaries from an index expression for assignment, mark the expression as assigning.
This avoids the temporaries encountering a range error with nested associative arrays.
https://github.com/dlang/dmd/pull/10422