Thread overview
D Inheritance bug - test.d
Jan 07, 2005
D Trebbien
Jan 07, 2005
John Reimer
Jan 07, 2005
Thomas Kuehne
Jan 07, 2005
Thomas Kuehne
Jan 08, 2005
John Reimer
Jan 08, 2005
Simon Buchan
Jan 09, 2005
David L. Davis
Jan 14, 2005
Simon Buchan
Jan 14, 2005
David L. Davis
Mar 11, 2005
D. Trebbien
January 07, 2005
class A
{
void test(int val)
{
}
}

class B : A
{
void test()
{
}
}

int main(char[][] args)
{
B b=new B();
b.test(6);

return 0;
}

(this code is attached for reference)

test.d(18): function test () does not match argument types (int)
test.d(18): Error: expected 0 arguments, not 1


January 07, 2005
D Trebbien wrote:
> class A
> {
> void test(int val)
> {
> }
> }
> 
> class B : A
> {
> void test()
> {
> }
> }
> 
> int main(char[][] args)
> {
> B b=new B();
> b.test(6);
> 
> return 0;
> }
> 
> (this code is attached for reference)
> 
> test.d(18): function test () does not match argument types (int)
> test.d(18): Error: expected 0 arguments, not 1
> 
> 

This isn't a bug.  This is the way D name resolution works.  If you want to be able to use class A's test() from a B object, you'll have to define an alias to it that brings it into B's namespace.

You might like to do a search of this newsgroup for a more detailed explanation of why D does name resolution this way. A fair bit of discussion about this has already taken place.

Later,

John
January 07, 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Added to DStress as: http://dstress.kuehne.cn/run/run/overload_12.d http://dstress.kuehne.cn/run/run/overload_13.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFB3wDh3w+/yD4P9tIRAnxdAJ40vwfHWMHBhN/csXXqMUlcPd1TggCgkknb
zgVBfFPug071TTrk5SlLY8c=
=6HHY
-----END PGP SIGNATURE-----
January 07, 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> Added to DStress as: http://dstress.kuehne.cn/run/run/overload_12.d http://dstress.kuehne.cn/run/run/overload_13.d

Arg... shouldn't switch languages that often ... http://dstress.kuehne.cn/nocompile/overload_12.d http://dstress.kuehne.cn/nocompile/overload_13.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFB3wPW3w+/yD4P9tIRAp6GAJ9mtlp4QwXfJ4q+G0kbL8GDhazNqACgyXUc
Bx3GLWkPGMkgr68d2HlOFn0=
=mipW
-----END PGP SIGNATURE-----
January 08, 2005
Thomas Kuehne wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> 
>>Added to DStress as:
>>http://dstress.kuehne.cn/run/run/overload_12.d
>>http://dstress.kuehne.cn/run/run/overload_13.d
> 
> 
> Arg... shouldn't switch languages that often ...
> http://dstress.kuehne.cn/nocompile/overload_12.d
> http://dstress.kuehne.cn/nocompile/overload_13.d
> 
> Thomas
> 
> 
> -----BEGIN PGP SIGNATURE-----
> 
> iD8DBQFB3wPW3w+/yD4P9tIRAp6GAJ9mtlp4QwXfJ4q+G0kbL8GDhazNqACgyXUc
> Bx3GLWkPGMkgr68d2HlOFn0=
> =mipW
> -----END PGP SIGNATURE-----

I know the example looks like an error in method overloading, but doesn't overloading specifically refer to use of methods with the same name (with different parameters) within the same class.  D doesn't automatically bring superclass methods of the same name into the subclass's name space (or whatever you call it) by design.  Since this is part of D's design, this is not a issue of incorrect overloading (though, I'm sure, some people wish it were).

I remember this D "feature" being haggled over in detail.  Some OOP programmer's found the D mechanism distasteful, especially those that came from a Java background.  But, I believe Walter has indicated ferverently that this is the way D was designed and the only sane way for the language to work. Correct me if I'm wrong.

Later,

John
January 08, 2005
On Fri, 07 Jan 2005 16:20:03 -0800, John Reimer <brk_6502@yahoo.com> wrote:

> Thomas Kuehne wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>>
>>> Added to DStress as:
>>> http://dstress.kuehne.cn/run/run/overload_12.d
>>> http://dstress.kuehne.cn/run/run/overload_13.d
>>
>>
>> Arg... shouldn't switch languages that often ...
>> http://dstress.kuehne.cn/nocompile/overload_12.d
>> http://dstress.kuehne.cn/nocompile/overload_13.d
>>
>> Thomas
>>
>>
>> -----BEGIN PGP SIGNATURE-----
>>
>> iD8DBQFB3wPW3w+/yD4P9tIRAp6GAJ9mtlp4QwXfJ4q+G0kbL8GDhazNqACgyXUc
>> Bx3GLWkPGMkgr68d2HlOFn0=
>> =mipW
>> -----END PGP SIGNATURE-----
>
> I know the example looks like an error in method overloading, but
> doesn't overloading specifically refer to use of methods with the same
> name (with different parameters) within the same class.  D doesn't
> automatically bring superclass methods of the same name into the
> subclass's name space (or whatever you call it) by design.  Since this
> is part of D's design, this is not a issue of incorrect overloading
> (though, I'm sure, some people wish it were).
>
> I remember this D "feature" being haggled over in detail.  Some OOP
> programmer's found the D mechanism distasteful, especially those that
> came from a Java background.  But, I believe Walter has indicated
> ferverently that this is the way D was designed and the only sane way
> for the language to work. Correct me if I'm wrong.
>
> Later,
>
> John
>

Hmm.... Not wanting to open a can of worms here, but I can see both sides
of this, clear and clean syntax, or in-your-face lists of all overloaded
fuctions, so you KNOW what could be called. However, with no implicit casting
of classes, and the fact that non-overloaded functions are still brought in,
I would have to go with not requiring aliasing.

Huge volumes of aliases for overloading probably means you're doing
something wrong, in any case.

Could this just be the default private access? I think that probably was
just cut for space.

--
"Yes, the american troops have advanced further. This will only
make it easier for us to defeat them" - Iraqi Information Minister
Muhammed Saeed al-Sahaf
January 09, 2005
In article <crmrb6$2slf$1@digitaldaemon.com>, D Trebbien says...
>
>class A
>{
>void test(int val)
>{
>}
>}
>
>class B : A
>{
>void test()
>{
>}
>}
>
>int main(char[][] args)
>{
>B b=new B();
>b.test(6);
>
>return 0;
>}
>
>(this code is attached for reference)
>
>test.d(18): function test () does not match argument types (int)
>test.d(18): Error: expected 0 arguments, not 1
>
>
>begin 0644 test.d
>M8VQA<W,@00T*>PT*("`@=F]I9"!T97-T*&EN="!V86PI#0H@("![#0H@("!]
>M#0I]#0H-"F-L87-S($(@.B!!#0I[#0H@("!V;VED('1E<W0H*0T*("`@>PT*
>M("`@?0T*?0T*#0II;G0@;6%I;BAC:&%R6UU;72!A<F=S*0T*>PT*("`@0B!B
>M/6YE=R!"*"D[#0H@("!B+G1E<W0H-BD[#0H-"B`@(')E='5R;B`P.PT*?0T*
>`
>end

D Trebbien : Below may be a way to do what you what without an alias.

# // class_inhert2.d
# private import std.stdio;
#
# interface I
# {
#     void test();
#     void test( in int );
# }
#
# class A : I
# {
#     // Had to add void test()
#     void test() { writefln( "B.test() Called."); }
#     void test( in int iVal )
#     {
#         writefln( "A.test( in int iVal=\"%s\" ) Called.", iVal ); }
#     }
#
# class B : A
# {
#     void test() { writefln( "B.test() Called."); }
# }
#
# int main( char[][] args )
# {
#     B b = new B();
#
#     // Interfaces can be inherited and functions overridden
#     I ob = cast(I) b;
#     ob.test(6);
#     ob.test();
#
#     return 0;
# }

Output:
C:\dmd>bin\dmd class_inhert2.d
C:\dmd\bin\..\..\dm\bin\link.exe class_inhert2,,,user32+kernel32/noi;

C:\dmd>class_inhert2
A.test( in int iVal="6" ) Called.
B.test() Called.

C:\dmd>

David L.

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
January 14, 2005
On Sun, 9 Jan 2005 01:47:42 +0000 (UTC), David L. Davis <SpottedTiger@yahoo.com> wrote:

> In article <crmrb6$2slf$1@digitaldaemon.com>, D Trebbien says...
>>
>> class A
>> {
>> void test(int val)
>> {
>> }
>> }
>>
>> class B : A
>> {
/* added */ alias void super.test(int) void test(int); // Is this the syntax?
>> void test()
>> {
>> }
>> }
>>
>> int main(char[][] args)
>> {
>> B b=new B();
>> b.test(6);
>>
>> return 0;
>> }
<snip>
> # // class_inhert2.d
> # private import std.stdio;
> #
> # interface I
> # {
> #     void test();
> #     void test( in int );
> # }
> #
> # class A : I
> # {
> #     // Had to add void test()
> #     void test() { writefln( "B.test() Called."); }
> #     void test( in int iVal )
> #     {
> #         writefln( "A.test( in int iVal=\"%s\" ) Called.", iVal ); }
> #     }
> #
> # class B : A
> # {
> #     void test() { writefln( "B.test() Called."); }
> # }
> #
> # int main( char[][] args )
> # {
> #     B b = new B();
> #
> #     // Interfaces can be inherited and functions overridden
> #     I ob = cast(I) b;
> #     ob.test(6);
> #     ob.test();
> #
> #     return 0;
> # }
<snip>

The cure is worse than the disease...

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
January 14, 2005
In article <opskk2ado1stcuho@simon>, Simon Buchan says...
>
>The cure is worse than the disease...

Simon Buchan: :P Please, feel free to cough up better cure besides the alias approach, which of course adds it's very own set of problems. Thus far, you haven't added anything positive to this topic...maybe it's time you did. :))

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
March 11, 2005
David L. Davis wrote:
> In article <crmrb6$2slf$1@digitaldaemon.com>, D Trebbien says...
> 
>>class A
>>{
>>void test(int val)
>>{
>>}
>>}
>>
>>class B : A
>>{
>>void test()
>>{
>>}
>>}
>>
>>int main(char[][] args)
>>{
>>B b=new B();
>>b.test(6);
>>
>>return 0;
>>}
>>
>>(this code is attached for reference)
>>
>>test.d(18): function test () does not match argument types (int)
>>test.d(18): Error: expected 0 arguments, not 1
>>
>>
>>begin 0644 test.d
>>M8VQA<W,@00T*>PT*("`@=F]I9"!T97-T*&EN="!V86PI#0H@("![#0H@("!]
>>M#0I]#0H-"F-L87-S($(@.B!!#0I[#0H@("!V;VED('1E<W0H*0T*("`@>PT*
>>M("`@?0T*?0T*#0II;G0@;6%I;BAC:&%R6UU;72!A<F=S*0T*>PT*("`@0B!B
>>M/6YE=R!"*"D[#0H@("!B+G1E<W0H-BD[#0H-"B`@(')E='5R;B`P.PT*?0T*
>>`
>>end
> 
> 
> D Trebbien : Below may be a way to do what you what without an alias.
> 
> # // class_inhert2.d
> # private import std.stdio;
> #
> # interface I
> # {
> #     void test();
> #     void test( in int );
> # }
> #
> # class A : I
> # { #     // Had to add void test()
> #     void test() { writefln( "B.test() Called."); }
> #     void test( in int iVal ) #     { #         writefln( "A.test( in int iVal=\"%s\" ) Called.", iVal ); }
> #     }
> #
> # class B : A
> # {
> #     void test() { writefln( "B.test() Called."); }
> # }
> # # int main( char[][] args )
> # {
> #     B b = new B();
> #     #     // Interfaces can be inherited and functions overridden
> #     I ob = cast(I) b;
> #     ob.test(6);
> #     ob.test();
> #     #     return 0;
> # }
> 
> Output:
> C:\dmd>bin\dmd class_inhert2.d
> C:\dmd\bin\..\..\dm\bin\link.exe class_inhert2,,,user32+kernel32/noi;
> 
> C:\dmd>class_inhert2
> A.test( in int iVal="6" ) Called.
> B.test() Called.
> 
> C:\dmd>
> 
> David L.
> 
> -------------------------------------------------------------------
> "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"

This is a great solution (and makes more sense to me in terms of OO design). Thanks David L.