This fails with 'function `S.test!((a) => a).test` need this to access member test':
struct S {
pragma(msg, test!(a => a));
}
int test(alias fn)() {
return fn(3);
}
Clearly, a => a does not need access to `this` in S, and something's gone wrong in the inference here.
Comment #1 by contact — 2020-10-19T17:04:50Z
This also happens on accessing static fields on a struct.
auto foobar(alias func)(string val)
{
return func(val);
}
struct S {
static immutable foo = "foo";
static immutable bar = foobar!((v) => v[0])(S.foo);
}
Comment #2 by contact — 2020-10-19T17:40:41Z
This seems related to what's happening on #21332.
When type is explicitly known on the lambda, this doesn't happen. See this snippet here:
```d
auto foobar(alias func)(string val)
{
return func(val);
}
struct S {
static immutable foo = "foo";
static immutable bar = foobar!((string v) => v[0])(S.foo);
}
```
This is the exact same code snippet reported on the latest comment, but the type of `v` is explicitly declared.
Comment #3 by robert.schadek — 2024-12-13T19:04:39Z