www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10815] New: Allow access of a symbol in a template instance if instantiator module has access to the symbol

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10815

           Summary: Allow access of a symbol in a template instance if
                    instantiator module has access to the symbol
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-13
05:13:21 PDT ---
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(); }
-----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 13 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10815


Dicebot <public dicebot.lv> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |public dicebot.lv


--- Comment #1 from Dicebot <public dicebot.lv> 2013-08-13 06:36:12 PDT ---
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)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 13 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10815



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-13
11:43:44 PDT ---
Well it may be intentional, but it makes many Phobos functions unusable with
internal library routines.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 13 2013