Currently the compiler disallows the following: ----- module test; import std.algorithm; private int foo(int input) { return input; } package int bar(int input) { return input; } void main() { map!foo([1, 2, 3]); map!bar([1, 2, 3]); } ----- C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(410): Error: function test.foo is not accessible from module algorithm C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(410): Error: function test.bar is not accessible from module algorithm The 'test' module explicitly passed a function that this module has access to, which should effectively give access of this function symbol to the instantiated template. I propose we allow the instantiated template to get access to the passed symbol if it's passed via an alias symbol, and if the module that instantiates the template has access to this symbol. Note that it is already possible to pass private functions via a pointer: ----- module test; import bar; private void func() { } void main() { call(&func); } ----- ----- module bar; void call(void function() func) { func(); } ----- This compiles. But with the relaxed access rule so should this (which currently doesn't compile): ----- module test; import bar; private void func() { } void main() { call!func(); } ----- ----- module bar; void call(alias func)() { func(); } -----
I have always thought it is intentional: "TemplateInstantances are always performed in the scope of where the TemplateDeclaration is declared, with the addition of the template parameters being declared as aliases for their deduced types." (http://dlang.org/template.html)
Well it may be intentional, but it makes many Phobos functions unusable with internal library routines.
I cannot reproduce this. It seems that it has been fixed in git master.