https://d.puremagic.com/issues/show_bug.cgi?id=11886
Kenji Hara <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|rejects-valid | Severity|regression |enhancement --- Comment #1 from Kenji Hara <[email protected]> 2014-01-09 18:08:11 PST --- The change is introduced by fixing bug 9050 (5fb19ce). But it's not a regression. With old versions, the OP code had been *wrongly* accepted. So it was accepts-invalid bug. The error message is intended and reject invalid code expectedly. === To be things more clear, I'd explain a current limitation. Currently, D/dmd does not support nested context inference for indirectly instantiated template lambdas. It is known limitation (at least to me). For example following case does not work: struct Lambda(alias fun) { auto opCall(A...)(A args) { return fun(args); } // Line 3 } void main() { int n = 10; Lambda!(x => x + n) f; assert(f(1) == 11); // Line 9 } Output: test.d(3): Error: function test.main.Lambda!((x) => x + n).Lambda.opCall!(int).opCall cannot access frame of function D main test.d(9): Error: template instance test.main.Lambda!((x) => x + n).Lambda.opCall!(int) error instantiating The template lambda x => x + n has context access (reading local variable n declared in main). But, until Lambda.opCall is instantiated, the 'nestedness' is unknown. Therefore compiler won't supply hidden member for Lambda!(x => x + n) struct object. Finally, f(1) will call `fun` from instantiated opCall method, but it does not know the context pointer of main function, so fun(args) makes the error "cannot access frame of function D main". Because of the limitation, currently it is impossible to create polymorpthic lambda by using existing language primitives. === The OP code hits the limitation. By the dmd bug, it had been wrongly accepted. But currently it is fixed and expectedly rejected. So, I'll change this issue to 'enhancement'. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
