Bug 15411 – Function literal accessing variable in declaration scope produces bad error message with inline call
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-12-06T02:01:00Z
Last change time
2017-08-02T08:07:26Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
dhasenan
Comments
Comment #0 by dhasenan — 2015-12-06T02:01:49Z
---
// 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.
Comment #1 by k.hara.pg — 2015-12-06T03:53:14Z
That's an incomplete access check of enclosing function frame in front end.
In the first case, the error message is generated by glue-layer, so it shows no message with -o- switch.
In https://github.com/D-Programming-Language/dmd/pull/5271, the frame access check issue will be fixed properly, then error message will also be consistent and generated by front end.
I added a diagnostic test case for this issue into the PR 5271.
Comment #2 by github-bugzilla — 2016-02-02T03:02:16Z