digitalmars.D.bugs - toString() not working within class member function?
- Nick Sabalausky (37/37) Feb 01 2005 The following code generates an error:
- Nick Sabalausky (3/41) Feb 01 2005 This is with DMD 0.110. I haven't tried 0.112 yet.
- Nick Sabalausky (3/49) Feb 01 2005 I just tried DMD 0.112 and got the same results.
- zwang (4/46) Feb 01 2005 I don't think this is a bug, because MyClass derives from Object and
- Nick Sabalausky (11/56) Feb 01 2005 Ahh, I see. Now that you mention that, it's occurred to me that the modu...
- Thomas Kuehne (14/14) Feb 02 2005 -----BEGIN PGP SIGNED MESSAGE-----
- Regan Heath (19/25) Feb 02 2005 I believe it is, my reasoning:
- Thomas Kuehne (36/36) Feb 02 2005 -----BEGIN PGP SIGNED MESSAGE-----
- Walter (5/35) Mar 16 2005 It follows the rule that name resolution happens before overload resolut...
- Thomas Kuehne (12/17) Mar 17 2005 -----BEGIN PGP SIGNED MESSAGE-----
The following code generates an error: ----- import std.string; class MyClass { void Display() { toString(1); // This line generates an error } } void main(char[][] args) { } ------ The compiler error is: test.d(7): function object.Object.toString () does not match argument types (int) test.d(7): Error: expected 0 arguments, not 1 The following variations compile fine: ----- import std.string; class MyClass { void Display() { std.string.toString(1); // Works fine } } void main(char[][] args) { } ----- void main(char[][] args) { toString(1); // Works fine } -----
Feb 01 2005
This is with DMD 0.110. I haven't tried 0.112 yet. "Nick Sabalausky" <z a.a> wrote in message news:ctpknf$21se$1 digitaldaemon.com...The following code generates an error: ----- import std.string; class MyClass { void Display() { toString(1); // This line generates an error } } void main(char[][] args) { } ------ The compiler error is: test.d(7): function object.Object.toString () does not match argument types (int) test.d(7): Error: expected 0 arguments, not 1 The following variations compile fine: ----- import std.string; class MyClass { void Display() { std.string.toString(1); // Works fine } } void main(char[][] args) { } ----- void main(char[][] args) { toString(1); // Works fine } -----
Feb 01 2005
I just tried DMD 0.112 and got the same results. "Nick Sabalausky" <z a.a> wrote in message news:ctpkqk$21ud$1 digitaldaemon.com...This is with DMD 0.110. I haven't tried 0.112 yet. "Nick Sabalausky" <z a.a> wrote in message news:ctpknf$21se$1 digitaldaemon.com...The following code generates an error: ----- import std.string; class MyClass { void Display() { toString(1); // This line generates an error } } void main(char[][] args) { } ------ The compiler error is: test.d(7): function object.Object.toString () does not match argument types (int) test.d(7): Error: expected 0 arguments, not 1 The following variations compile fine: ----- import std.string; class MyClass { void Display() { std.string.toString(1); // Works fine } } void main(char[][] args) { } ----- void main(char[][] args) { toString(1); // Works fine } -----
Feb 01 2005
I don't think this is a bug, because MyClass derives from Object and inherits the "char[] toString()" method which takes no argument. You have to explicitly write std.string.toString here. Nick Sabalausky wrote:The following code generates an error: ----- import std.string; class MyClass { void Display() { toString(1); // This line generates an error } } void main(char[][] args) { } ------ The compiler error is: test.d(7): function object.Object.toString () does not match argument types (int) test.d(7): Error: expected 0 arguments, not 1 The following variations compile fine: ----- import std.string; class MyClass { void Display() { std.string.toString(1); // Works fine } } void main(char[][] args) { } ----- void main(char[][] args) { toString(1); // Works fine } -----
Feb 01 2005
Ahh, I see. Now that you mention that, it's occurred to me that the module scope operator works too: class MyClass { void Display() { .toString(1); // That little dot does wonders ;) } } "zwang" <nehzgnaw gmail.com> wrote in message news:ctpldp$22ba$1 digitaldaemon.com...I don't think this is a bug, because MyClass derives from Object and inherits the "char[] toString()" method which takes no argument. You have to explicitly write std.string.toString here. Nick Sabalausky wrote:The following code generates an error: ----- import std.string; class MyClass { void Display() { toString(1); // This line generates an error } } void main(char[][] args) { } ------ The compiler error is: test.d(7): function object.Object.toString () does not match argument types (int) test.d(7): Error: expected 0 arguments, not 1 The following variations compile fine: ----- import std.string; class MyClass { void Display() { std.string.toString(1); // Works fine } } void main(char[][] args) { } ----- void main(char[][] args) { toString(1); // Works fine } -----
Feb 01 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Added to DStress as http://dstress.kuehne.cn/run/overload_14.d http://dstress.kuehne.cn/run/overload_15.d http://dstress.kuehne.cn/run/overload_16.d Note: this behavior might actually be the desired one, but I couldn't find and documentation stating so. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCAaIr3w+/yD4P9tIRAsf0AKDQL1sT7nI610T1FyWJe1olNp3TpQCggtl2 iEEAmvefYHMDyf4+rQleOLQ= =YtOV -----END PGP SIGNATURE-----
Feb 02 2005
On Thu, 03 Feb 2005 05:01:47 +0100, Thomas Kuehne <thomas-dloop kuehne.THISISSPAM.cn> wrote:Added to DStress as http://dstress.kuehne.cn/run/overload_14.d http://dstress.kuehne.cn/run/overload_15.d http://dstress.kuehne.cn/run/overload_16.d Note: this behavior might actually be the desired one, but I couldn't find and documentation stating so.I believe it is, my reasoning: The class inherits a toString method from it's parent "Object". When you type "toString(1);" in a class method, name resolution begins by looking for a symbol called toString in the current scope, i.e. the class, then it looks in the parent class, finds toString() and gives an error because the number of parameters is all wrong. The solution is to explicitly call the function you mean, or add an alias to the class eg. class MyClass { alias std.string.toString toString; void Display() { toString(1); // This line generates an error } } Regan
Feb 02 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Regan Heath wrote: | On Thu, 03 Feb 2005 05:01:47 +0100, Thomas Kuehne | <thomas-dloop kuehne.THISISSPAM.cn> wrote: | |> Added to DStress as |> |> http://dstress.kuehne.cn/run/overload_14.d |> http://dstress.kuehne.cn/run/overload_15.d |> http://dstress.kuehne.cn/run/overload_16.d |> |> Note: this behavior might actually be the desired one, but I |> couldn't find and documentation stating so. | | | I believe it is, my reasoning: | | The class inherits a toString method from it's parent "Object". | | When you type "toString(1);" in a class method, name resolution | begins by looking for a symbol called toString in the current scope, | i.e. the class, then it looks in the parent class, finds toString() | and gives an error because the number of parameters is all wrong. The documentation is missing the statement about scoping-overloading interaction. The documentation only talks about overloading functions in base classes and not about overloading functions that are part of the class' parent scope(non-class member functions or class member functions of enclosing classes). Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCAayx3w+/yD4P9tIRAgMfAJ9uBPrmFGULtjMmmbhL4cZx/5W/YwCgyAr/ nro2a4asxLmLUn9RRJ1xv7Y= =/RMz -----END PGP SIGNATURE-----
Feb 02 2005
"Thomas Kuehne" <thomas-dloop kuehne.THISISSPAM.cn> wrote in message news:ium8d2-vq3.ln1 lnews.kuehne.cn...-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Regan Heath wrote: | On Thu, 03 Feb 2005 05:01:47 +0100, Thomas Kuehne | <thomas-dloop kuehne.THISISSPAM.cn> wrote: | |> Added to DStress as |> |> http://dstress.kuehne.cn/run/overload_14.d |> http://dstress.kuehne.cn/run/overload_15.d |> http://dstress.kuehne.cn/run/overload_16.d |> |> Note: this behavior might actually be the desired one, but I |> couldn't find and documentation stating so. | | | I believe it is, my reasoning: | | The class inherits a toString method from it's parent "Object". | | When you type "toString(1);" in a class method, name resolution | begins by looking for a symbol called toString in the current scope, | i.e. the class, then it looks in the parent class, finds toString() | and gives an error because the number of parameters is all wrong. The documentation is missing the statement about scoping-overloading interaction. The documentation only talks about overloading functions in base classes and not about overloading functions that are part of the class' parent scope(non-class member functions or class member functions of enclosing classes).It follows the rule that name resolution happens before overload resolution. Names outside the scope where the name was found do not participate in overload resolution.
Mar 16 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Walter schrieb am Wed, 16 Mar 2005 13:39:13 -0800:Thanks - moved to http://dstress.kuehne.cn/nocompile/overload_14.d http://dstress.kuehne.cn/nocompile/overload_16.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCOZuO3w+/yD4P9tIRAmJ+AKCtfo4hD8YAMtimM1Ggvy1om6TFagCgwPEv lPSlLGI/f//XnaZhNDaqcXI= =eJs/ -----END PGP SIGNATURE-----|> http://dstress.kuehne.cn/run/overload_14.d |> http://dstress.kuehne.cn/run/overload_16.dIt follows the rule that name resolution happens before overload resolution. Names outside the scope where the name was found do not participate in overload resolution.
Mar 17 2005