www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2563] New: Derived class is implicitly castable to Base class when inherited privately

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

           Summary: Derived class is implicitly castable to Base class when
                    inherited privately
           Product: D
           Version: 2.023
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: 2korden gmail.com


module A;

class A1
{
    void foo();
}

class A2 : private A1
{
}

module B;

void main() {
    A2 a2 = new A2();
    // a2.foo(); // Error: class A.A2 member foo is not accessible

    A1 a1 = a2;  // This line should yield an error
    a1.foo();    // ta-dam! Private method invoked
}


-- 
Jan 07 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2563





------- Comment #1 from jarrett.billingsley gmail.com  2009-01-07 14:10 -------
Why is public/private/protected inheritance even supported?  I think this is
more a strange artifact in the compiler/grammar than anything else.  When you
don't have MI, anything but public inheritance is useless.


-- 
Jan 07 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2563


spam extrawurst.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |spam extrawurst.org




------- Comment #2 from spam extrawurst.org  2009-01-07 14:22 -------
afaik public/private/protected inheritance is not supported in D it is just not
prohibited to write it like in the sample though it always is publicly
inherited. there should be a bug for enhancement to stop permiting this
confusing syntactical feature.


-- 
Jan 07 2009
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2563





------- Comment #3 from 2korden gmail.com  2009-01-07 14:29 -------
(In reply to comment #1)
 Why is public/private/protected inheritance even supported?  I think this is
 more a strange artifact in the compiler/grammar than anything else.  When you
 don't have MI, anything but public inheritance is useless.
 

No, it's useful to hide implementation details. --
Jan 07 2009
parent Extrawurst <spam extrawurst.org> writes:
d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=2563
 
 
 
 
 
 ------- Comment #3 from 2korden gmail.com  2009-01-07 14:29 -------
 (In reply to comment #1)
 Why is public/private/protected inheritance even supported?  I think this is
 more a strange artifact in the compiler/grammar than anything else.  When you
 don't have MI, anything but public inheritance is useless.

No, it's useful to hide implementation details.

wooops right its documented like this aswell. sorry, its a bug!
Jan 07 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2563


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Keywords|                            |accepts-invalid




------- Comment #4 from smjg iname.com  2009-01-07 15:36 -------
(In reply to comment #2)
 afaik public/private/protected inheritance is not supported in D it 
 is just not prohibited to write it like in the sample though it 
 always is publicly inherited.

What do you believe is the reason that D grammar goes out of its way to allow this syntax?
 there should be a bug for enhancement to stop permiting this 
 confusing syntactical feature.

Issue 177 Notice the real reason the feature doesn't make sense: it hides the methods defined in Object, which are meant to be part of every class. --
Jan 07 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2563


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #5 from Stewart Gordon <smjg iname.com> 2010-03-17 13:19:28 PDT ---
*** Issue 3774 has been marked as a duplicate of this issue. ***

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