Consider the following
void indirectCall(T)(T fn) {
pragma(msg, T);
}
__gshared int x;
void f() {
indirectCall({x++;}); // void function() nothrow @nogc @system
}
void g() pure {
indirectCall({x++;}); // pure delegate 'dtest.g.__lambda1' cannot access mutable static data 'x'
}
please ignore the mutable state issue -- the issue here that `{x++}` is treated as a function
Comment #1 by schveiguy — 2017-07-17T17:44:24Z
I'll add a note that it certainly is possible for a function to be inferred:
void foo() pure {
indirectCall(function() {x++;}); // void function() nothrow @nogc @system
}
The compiler should be able to do so.
Comment #2 by robert.schadek — 2024-12-13T18:53:26Z