Comment #0 by muhammed.yucel — 2021-11-12T10:48:06Z
It will throw the following compilation error
Error: indexing an associative array in `@nogc` function `app.myfunc` may cause
a GC allocation
Here is a code example:
immutable int[int] aa;
shared static this ()
{
aa[10] = 20;
aa[20] = 30;
}
int myfunc () @nogc
{
return aa[10];
}
Comment #1 by muhammed.yucel — 2021-12-14T13:38:57Z
Documentation (1) states the "why" for this error but I think it is also wrong. RangeError is statically allocated thus GC shouldn't be a problem but the actual problem is a new key may be allocated when indexing an AA (left side).
1: https://dlang.org/spec/function.html#nogc-functions
Comment #2 by robert.schadek — 2024-12-13T19:19:19Z