Bug 23531 – [DIP1000] scope variable can be assigned as AA key
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-12-01T19:20:43Z
Last change time
2022-12-03T06:25:34Z
Keywords
accepts-invalid, pull, safe
Assigned to
No Owner
Creator
Mathias LANG
Comments
Comment #0 by pro.mathias.lang — 2022-12-01T19:20:43Z
```
void main () @safe
{
auto r = bar();
assert(r["foo!"] == "oi");
}
string[string] bar () @safe
{
immutable(char)[4] s = "foo!";
return foo(s);
}
string[string] foo (scope string f) @safe
{
string[string] aa;
aa[f] = "oi";
return aa;
}
```
Results in RangeError because the key is garbage. Funny thing is that assigning `f` as the value of the AA (e.g. `aa[f] = f;`) is correctly detected.
Comment #1 by dlang-bot — 2022-12-01T21:17:30Z
@dkorpel created dlang/dmd pull request #14662 "Fix 23531 - scope variable can be assigned as AA key" fixing this issue:
- Fix 23531 - scope variable can be assigned as AA key
https://github.com/dlang/dmd/pull/14662
Comment #2 by dlang-bot — 2022-12-03T06:25:34Z
dlang/dmd pull request #14662 "Fix 23531 - scope variable can be assigned as AA key" was merged into master:
- 33067414ffcb01f8d534f8fe621cbffd04e2fb14 by Dennis Korpel:
Fix 23531 - scope variable can be assigned as AA key
https://github.com/dlang/dmd/pull/14662