https://issues.dlang.org/show_bug.cgi?id=22497
--- Comment #2 from Andrei Alexandrescu <[email protected]> --- (In reply to kinke from comment #1) > AFAIK, the problem is that the alias template parameter doesn't capture the > context if bound to a nested function, unlike a delegate runtime parameter. > `canon!"abc".fun!<delegateLambda>` would need a hidden context runtime > parameter to forward to the lambda invocation: > > auto canon!"abc".fun!<lambda>(void* __lambda_context, int x) { > return <lambda>(__lambda_context, x); > } > > void main() { > int x = 42; > canon!"abc".fun!(y => y + x)(<main_context>, 1); > } Not sure I understand but hopefully it's something that can be fixed, right? Things would be different if the template itself took an alias parameter that could be bound to a distinct context. But it being a string makes all the difference. Also forgot to mention that this code also doesn't work but for a different reason: template canon(string v) { static auto fun(alias lambda)(int x) { return lambda(x); } } alias f1 = canon!"abc".fun; void main() { int x = 42; f1!(y => y + x)(1); } Error: `static` function `onlineapp.main.f1!((y) => y + x).fun` cannot access delegate `__lambda2` in frame of function `D main` --
