This particular code fails with a compile error that it shouldn't.
```
@nogc:
void main() {
int x = 0;
f((int, immutable size_t) {
int y = x;
});
}
void f(T)(scope void delegate(T, immutable size_t) @nogc cb) {
cb(0, 0);
}
```
When I run `dmd app.d` this fails with:
```
app.d(3): Error: function D main is @nogc yet allocates closures with the GC
app.d(5): app.main.__lambda1 closes over variable x at app.d(4)
```
There is no compile error if:
* The second delegate parameter is something other than `immutable size_t` (such as `size_t` or `immutable bool`).
* An explicit type argument is given to `f`, as in `f!int`.
* The delegate parameters are named, as in `f((int a, immutable size_t b) {`.
Comment #1 by ag0aep6g — 2020-08-16T10:42:29Z
(In reply to andy.pj.hanson from comment #0)
> f((int, immutable size_t) {
> int y = x;
> });
[...]
> * The delegate parameters are named, as in `f((int a, immutable size_t b) {`.
Note that the second parameter is actually already named in the non-working version. It's called "size_t". What's missing is the type. By adding "b", size_t gets recognized as the type as intended.
Slightly more reduced test case:
----
@nogc:
void main()
{
int x = 0;
f((int, b) {
int y = x;
});
}
void f(T)(scope void delegate(T, immutable int) @nogc cb) {}
----
Also happens with other qualifiers (const, shared) instead of immutable.
Comment #2 by robert.schadek — 2024-12-13T19:11:04Z