Bug 17063 – Nested function template cannot be accessed

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-01-06T11:22:44Z
Last change time
2022-11-14T14:08:35Z
Assigned to
No Owner
Creator
Jens Mueller

Comments

Comment #0 by jens.mueller — 2017-01-06T11:22:44Z
The following code does not compile with dmd v2.072.2. It gives test.d(3): Error: function test.__unittestL6_1.bar!cast(ubyte)0u.bar is a nested function and cannot be accessed from test.foo!(bar).foo void foo(alias fun)() { fun(); } unittest { // needs to be a template to cause the compilation to fail void bar(ubyte a = 0)() { } // workaround alias blub = bar!0; foo!blub(); foo!bar(); } The problem seems to be the function template. When the function template is explicitly initialized it works.
Comment #1 by schveiguy — 2022-04-15T04:14:18Z
Found another interesting case of this: ``` void main() { int x = 5; bool foo(T)(T arg) { return arg == x; } import std.functional; unaryFun!foo(5); // ok! testit!foo(5); // error } auto testit(alias pred, T)(T arg) { import std.functional; return unaryFun!pred(arg); } ``` Note that instantiating unaryFun!foo directly in the function works, but outside the function it doesn't. I can't see why it's different. Changing foo to: ``` bool foo(int arg) ``` Works in both cases. Clearly the frame is accessible.
Comment #2 by razvan.nitu1305 — 2022-11-14T14:08:35Z
*** This issue has been marked as a duplicate of issue 5710 ***