digitalmars.D.bugs - [Issue 15411] New: Function literal accessing variable in
- via Digitalmars-d-bugs (40/40) Dec 05 2015 https://issues.dlang.org/show_bug.cgi?id=15411
https://issues.dlang.org/show_bug.cgi?id=15411 Issue ID: 15411 Summary: Function literal accessing variable in declaration scope produces bad error message with inline call Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Keywords: diagnostic Severity: enhancement Priority: P4 Component: dmd Assignee: nobody puremagic.com Reporter: dhasenan gmail.com --- // not_nested_func.d void bar() { auto i = 0; auto j = (function() { return i; })(); } --- $ dmd not_nested_func.d not_nested_func.d(3): Error: function not_nested_func.bar is a nested function and cannot be accessed from not_nested_func.foo() Compare: --- // not_called.d void bar() { auto i = 0; auto fn = function() { return i; }; } --- $ dmd not_nested_func.d not_nested_func.d(3): Error: cannot match function literal to delegate type 'int delegate() pure nothrow nogc safe Here, the error message is confusing, but I at least get a hint that using 'delegate' in place of 'function' might help. Tested on 2.069.2 and 2.069.0. --
Dec 05 2015