[Issue 10996] New: Subtyping with "alias this" conflicts with private base type

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 8 04:46:19 PDT 2013


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 at puremagic.com
        ReportedBy: joseph.wakeling at webdrake.net


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


More information about the Digitalmars-d-bugs mailing list