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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 13 05:13:23 PDT 2013


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 at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at 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: -------


More information about the Digitalmars-d-bugs mailing list