www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10996] New: Subtyping with "alias this" conflicts with private base type

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

           Summary: Subtyping with "alias this" conflicts with private
                    base type
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: joseph.wakeling webdrake.net



2013-09-08 04:46:17 PDT ---
Created an attachment (id=1246)
Module defining a simple subtype.

Consider a simple subtyping example, in the spirit of that given on TDPL p.
231.

    class Foo
    {
        public int a;
    }

    class Bar
    {
        private Foo _base;
        alias _base this;

        this()
        {
            _base = new Foo;
        }
    }

Theoretically, the public member .a of Foo should be publicly available via
Bar, as the alias itself is public.  However, in practice, any attempt to
access it from outside the module will result in an error:

  Error: class subtype.Bar member _base is not accessible

Full example code is attached -- run

  rdmd -main -unittest subtype.d

... to see how access to Bar.a works from within the module, and then

  rdmd subtypemain.d

... to see it failing when accessed from outside.

The ability to have a private instance of the base type is clearly desirable
because you don't want the user to be able to access Bar._base directly. 
However, the public alias should mean that public methods of _base are made
public via Bar's interface.

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




2013-09-08 04:47:10 PDT ---
Created an attachment (id=1247)
Main program file that imports the subtype module.  Run to see the bug in
action.

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




2013-09-17 03:09:41 PDT ---
The issue also affects module-level aliases, e.g.:

    alias fun = Impl!int;

    private template Impl(T)
    {
        void Impl(){}
    }

See: http://forum.dlang.org/thread/sqtmfbzusxzchuncfsoh forum.dlang.org

Example benefit for this kind of aliasing: the programmer can define a private
implementation that takes a variety of template parameters, and make publicly
available only instantiations with a sane choice of parameter values (could be
useful for e.g. random number generators).

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