digitalmars.D.bugs - [Issue 24256] New: `-preview=in` should allow array literals and
- d-bugmail puremagic.com (39/39) Nov 22 2023 https://issues.dlang.org/show_bug.cgi?id=24256
https://issues.dlang.org/show_bug.cgi?id=24256 Issue ID: 24256 Summary: `-preview=in` should allow array literals and delegate literals in a ` nogc` context Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: ogion.art gmail.com DMD allows passing array literals and delegate literals to `scope` parameters in nogc functions: void foo(const scope int[]) nogc {} void bar(scope void delegate()) nogc {} void main() nogc { foo([1, 2, 3]); int x; bar(() { x++; }); } I expect this to work with `in` parameters as well, since “input parameters behave as if they have the `const scope` storage classes” according to spec. But as of DMD v2.105.3 this fails to compile (`-preview=in` enabled): void foo(in int[]) nogc {} void bar(in void delegate()) nogc {} void main() nogc { foo([1, 2, 3]); int x; bar(() { x++; }); } app.d(4): Error: array literal in ` nogc` function `D main` may cause a GC allocation app.d(3): Error: function `D main` is ` nogc` yet allocates closure for `main()` with the GC app.d(6): `app.main.__lambda2` closes over variable `x` at app.d(5) --
Nov 22 2023