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: [email protected]
          Reporter: [email protected]

---
// 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.

--

Reply via email to