[Issue 23531] New: [DIP1000] scope variable can be assigned as AA key
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Dec 1 19:20:43 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23531
Issue ID: 23531
Summary: [DIP1000] scope variable can be assigned as AA key
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: pro.mathias.lang at gmail.com
```
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.
--
More information about the Digitalmars-d-bugs
mailing list