digitalmars.D - A bug with matching overloaded functions?
- flyinghearts (15/15) Dec 01 2010 void check(string s) {}
- Jonathan M Davis (8/31) Dec 01 2010 Not exactly. A string literal implictly casts to all 3 string types. You...
- Steven Schveighoffer (11/47) Dec 01 2010 I think it's a bug. This compiles:
void check(string s) {} void check(wstring s) {} void check(dstring s) {} void main() { check("test"); //check("test"c); } D:\Desktop\d\zb.d(7): Error: function zb.check called with argument types: ((string)) matches both: zb.check(string s) and: zb.check(immutable(dchar)[] s) The type of "test" is string, isn't it?
Dec 01 2010
On Wednesday, December 01, 2010 08:42:23 flyinghearts wrote:void check(string s) {} void check(wstring s) {} void check(dstring s) {} void main() { check("test"); //check("test"c); } D:\Desktop\d\zb.d(7): Error: function zb.check called with argument types: ((string)) matches both: zb.check(string s) and: zb.check(immutable(dchar)[] s) The type of "test" is string, isn't it?Not exactly. A string literal implictly casts to all 3 string types. You can add a suffix to force it to be a wstring or dstring (I don't think that there's a suffix for a normal string though), or you can cast it to the exact one you want, or you can assign it to a variable first. If you use auto, I believe that it will default to string rather than wstring or dstring, but string literals implicitly cast to all 3, so the compiler considers your code to be ambiguous. - Jonathan M Davis
Dec 01 2010
On Wed, 01 Dec 2010 13:58:25 -0500, Jonathan M Davis <jmdavisProg gmx.com> wrote:On Wednesday, December 01, 2010 08:42:23 flyinghearts wrote:I think it's a bug. This compiles: void check(int i) {} void check(long i) {} void check(short i) {} void main() { check(1); } -Stevevoid check(string s) {} void check(wstring s) {} void check(dstring s) {} void main() { check("test"); //check("test"c); } D:\Desktop\d\zb.d(7): Error: function zb.check called with argument types: ((string)) matches both: zb.check(string s) and: zb.check(immutable(dchar)[] s) The type of "test" is string, isn't it?Not exactly. A string literal implictly casts to all 3 string types. You can add a suffix to force it to be a wstring or dstring (I don't think that there's a suffix for a normal string though), or you can cast it to the exact one you want, or you can assign it to a variable first. If you use auto, I believe that it will default to string rather than wstring or dstring, but string literals implicitly cast to all 3, so the compiler considers your code to be ambiguous.
Dec 01 2010