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: nob...@puremagic.com
        ReportedBy: joseph.wakel...@webdrake.net


--- Comment #0 from Joseph Rushton Wakeling <joseph.wakel...@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: -------

Reply via email to