///////////// test.d ///////////// struct S { int i; alias field = i; int fun(alias pred)() const { // Doesn't work: //return pred(field); // Works: alias ipred = pred!int; return ipred(field); } alias fun1 = fun!(i => i + 1); } ////////////////////////////////// Error is: test.d(9,14): Error: template `test.S.__lambda5` cannot deduce function from argument types `!()(const(int)) const`, candidates are: test.d(16,20): `__lambda5` test.d(16,15): Error: template instance `test.S.fun!((i) => i + 1)` error instantiating
Isn't the real bug here the fact that calling ipred passes compilation? As far as I could tell the lambda template instantion is inside the scope of the S struct => you cannot call it from fun, since fun may call only const functions and pred is mutable.
Thanks for looking at this! (In reply to RazvanN from comment #1) > As > far as I could tell the lambda template instantion is inside the scope of > the S struct Hmm! But, shouldn't it infer that since it doesn't access anything other than its arguments, it should not have a context? I see that ipred is typed as a function not delegate. > you cannot call it from fun, since fun may call only const > functions and pred is mutable. Thanks, I actually didn't realize that fun being const was a crucial part of this. I guess the error message could be better.
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19629 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB