www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Polymorphism broken by 'package' visibility

reply "Kris" <fu bar.com> writes:
class Base
{
        package char[] name ()
        {
                return "base";
        }

        char[] test ()
        {
                return name();
        }
}

class Derived : Base
{
        package override char[] name()
        {
                return "derived";
        }
}

void main()
{
        Derived d = new Derived;

        // fails!
        assert (d.test() == "derived");
}


Derived.test() returns "base" instead of "derived" ... works as expected
with 'protected' etc.
May 19 2005
next sibling parent Thomas Kuehne <thomas-dloop kuehne.this-is.spam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kris schrieb am Thu, 19 May 2005 17:21:59 -0700:
 class Base
 {
         package char[] name ()
         {
                 return "base";
         }

         char[] test ()
         {
                 return name();
         }
 }

 class Derived : Base
 {
         package override char[] name()
         {
                 return "derived";
         }
 }

 void main()
 {
         Derived d = new Derived;

         // fails!
         assert (d.test() == "derived");
 }


 Derived.test() returns "base" instead of "derived" ... works as expected
 with 'protected' etc.
Added to DStress as http://dstress.kuehne.cn/run/o/overload_23.d http://dstress.kuehne.cn/run/o/overload_24.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCjdI33w+/yD4P9tIRAlZRAJoDgHjplaFgdrcS2hl+Im4d8aq/xQCeL/i2 hyLWrLWVSuOUmtplg0qhR0M= =Lxge -----END PGP SIGNATURE-----
May 20 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Kris" <fu bar.com> wrote in message news:d6jaj8$2r1n$1 digitaldaemon.com...
 Derived.test() returns "base" instead of "derived" ... works as expected
 with 'protected' etc.
This is as designed - 'private' and 'package' functions are not virtual.
May 20 2005
next sibling parent reply "Kris" <fu bar.com> writes:
Thanks for the clarification.

Private, sure. Package? That's a tad unexpected. I guess I must have missed
that in the documentation?



"Walter" <newshound digitalmars.com> wrote in message
news:d6lgva$1kd0$1 digitaldaemon.com...
 "Kris" <fu bar.com> wrote in message
news:d6jaj8$2r1n$1 digitaldaemon.com...
 Derived.test() returns "base" instead of "derived" ... works as expected
 with 'protected' etc.
This is as designed - 'private' and 'package' functions are not virtual.
May 20 2005
parent reply Ant <duitoolkit yahoo.ca> writes:
Kris wrote:
 Thanks for the clarification.
 
 Private, sure. Package? That's a tad unexpected.
what happened Kris? lost your fire? ;) It's absurd! :( well, not as bad as: - default on switch (even Walter was caught on this I'm surprised nobody referred it) - missing return - == null - legacy "compatibilities" (case, ~this(), cast...) - stupid name resolution rules - ... :p See Walter? D is so good that we even put up with these things! but somehow I always feel like "almost there..." :( Ant PS Kris, we are all expecting a 4 pages PDF...
May 20 2005
next sibling parent kris <fu bar.org> writes:
Ant wrote:
 Kris wrote:
 
 Thanks for the clarification.

 Private, sure. Package? That's a tad unexpected.
Hello, Ant ~ Long time!
 what happened Kris?
 lost your fire? ;)
Hell, no. I was just waiting for you <g>
 
 It's absurd! :(
I'd really like to hear why it /should/ be like it is ... anyone? <snip>
 PS Kris, we are all expecting a 4 pages PDF...
Better things to do; such as teaching this octopus to waltz, on just two legs :)
May 21 2005
prev sibling parent "Charlie" <charles jwavro.com> writes:
lol

"Ant" <duitoolkit yahoo.ca> wrote in message
news:d6mj4f$2bdp$1 digitaldaemon.com...
 Kris wrote:
 Thanks for the clarification.

 Private, sure. Package? That's a tad unexpected.
what happened Kris? lost your fire? ;) It's absurd! :( well, not as bad as: - default on switch (even Walter was caught on this I'm surprised nobody
referred it)
 - missing return
 - == null
 - legacy "compatibilities" (case, ~this(), cast...)
 - stupid name resolution rules
 - ...

 :p

 See Walter? D is so good that we even put up with these things!
 but somehow I always feel like "almost there..." :(

 Ant

 PS Kris, we are all expecting a 4 pages PDF...
May 23 2005
prev sibling parent =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Walter wrote:
| "Kris" <fu bar.com> wrote in message
| news:d6jaj8$2r1n$1 digitaldaemon.com...
|
|> Derived.test() returns "base" instead of "derived" ... works as
|> expected with 'protected' etc.
|
|
| This is as designed - 'private' and 'package' functions are not
| virtual.
|

http://digitalmars.com/d/function.html
All non-static non-private member functions are virtual.

Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCj4b83w+/yD4P9tIRAtCWAJ4hh+pZ3zPFsFgz6LW26Fo3W41RfACeIry/
rjcI1UFD/Yjaim0tUBa8Y3o=
=J6+2
-----END PGP SIGNATURE-----
May 21 2005