digitalmars.D.bugs - Implicit conversion bug?
- Kramer (24/24) Feb 09 2006 I can't tell if the following code is a bug, or if I need to throw in a ...
- Derek Parnell (22/51) Feb 09 2006 You could add these two functions to your code (or Phobos; hint, hint)
- Kramer (3/54) Feb 09 2006 Cool, thanks. That helps... and those would be nice in the standard lib...
- Kramer (25/76) Feb 10 2006 Not sure if this is supposed to be allowed for nested functions (couldn'...
- Thomas Kuehne (13/36) Feb 23 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Kramer (10/61) Feb 10 2006 This also compiles. You don't have to put in a try block to catch the u...
- Derek Parnell (8/18) Feb 10 2006 It might compile but its wrong to do it this way. A wchar is two-bytes
- Kramer (5/24) Feb 13 2006 Thanks, I'll be sure not to do it this way. I'm going from memeory here...
I can't tell if the following code is a bug, or if I need to throw in a cast somewhere. Produces this: bug.d(9): function std.string.toString called with argument types: (wchar) matches both: std.string.toString(char) and: std.string.toString(creal) I'm guessing it's matching by implicit conversions, but that's just a little confusing??? -Kramer
Feb 09 2006
On Fri, 10 Feb 2006 06:28:05 +0000 (UTC), Kramer wrote:I can't tell if the following code is a bug, or if I need to throw in a cast somewhere. Produces this: bug.d(9): function std.string.toString called with argument types: (wchar) matches both: std.string.toString(char) and: std.string.toString(creal) I'm guessing it's matching by implicit conversions, but that's just a little confusing??? -KramerYou could add these two functions to your code (or Phobos; hint, hint) char[] toString(wchar c) { wchar[] result; result.length = 1; result[0] = c; return std.utf.toUTF8(result); } char[] toString(dchar c) { dchar[] result; result.length = 1; result[0] = c; return std.utf.toUTF8(result); } -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 10/02/2006 5:36:19 PM
Feb 09 2006
In article <ah2r7az1frya.3xeee3qsuwd7$.dlg 40tude.net>, Derek Parnell says...On Fri, 10 Feb 2006 06:28:05 +0000 (UTC), Kramer wrote:Cool, thanks. That helps... and those would be nice in the standard lib. -KramerI can't tell if the following code is a bug, or if I need to throw in a cast somewhere. Produces this: bug.d(9): function std.string.toString called with argument types: (wchar) matches both: std.string.toString(char) and: std.string.toString(creal) I'm guessing it's matching by implicit conversions, but that's just a little confusing??? -KramerYou could add these two functions to your code (or Phobos; hint, hint) char[] toString(wchar c) { wchar[] result; result.length = 1; result[0] = c; return std.utf.toUTF8(result); } char[] toString(dchar c) { dchar[] result; result.length = 1; result[0] = c; return std.utf.toUTF8(result); } -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 10/02/2006 5:36:19 PM
Feb 09 2006
In article <ah2r7az1frya.3xeee3qsuwd7$.dlg 40tude.net>, Derek Parnell says...On Fri, 10 Feb 2006 06:28:05 +0000 (UTC), Kramer wrote:Not sure if this is supposed to be allowed for nested functions (couldn't find anything in the docs), but when both of the nested functions are there, it won't compile. Comment one or the other and it compiles clean. produces this: bug.d(12): declaration toString is already defined -KramerI can't tell if the following code is a bug, or if I need to throw in a cast somewhere. Produces this: bug.d(9): function std.string.toString called with argument types: (wchar) matches both: std.string.toString(char) and: std.string.toString(creal) I'm guessing it's matching by implicit conversions, but that's just a little confusing??? -KramerYou could add these two functions to your code (or Phobos; hint, hint) char[] toString(wchar c) { wchar[] result; result.length = 1; result[0] = c; return std.utf.toUTF8(result); } char[] toString(dchar c) { dchar[] result; result.length = 1; result[0] = c; return std.utf.toUTF8(result); } -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 10/02/2006 5:36:19 PM
Feb 10 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Kramer schrieb am 2006-02-10: [snip]Not sure if this is supposed to be allowed for nested functions (couldn't find anything in the docs), but when both of the nested functions are there, it won't compile. Comment one or the other and it compiles clean. produces this: bug.d(12): declaration toString is already definedhttp://digitalmars.com/d/function.html: | Unlike module level declarations, declarations within function scope | are processed in order. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFD/rwv3w+/yD4P9tIRAszCAJwOFpdqxKPksoI6+DGDSfoDnn8uUwCglw1u avPQyRLGKx+/zG8wmEv38Io= =i3GT -----END PGP SIGNATURE-----
Feb 23 2006
In article <ah2r7az1frya.3xeee3qsuwd7$.dlg 40tude.net>, Derek Parnell says...On Fri, 10 Feb 2006 06:28:05 +0000 (UTC), Kramer wrote:This also compiles. You don't have to put in a try block to catch the utf exception, but I'm not sure if this is any *better* necessarily because of the cast. -KramerI can't tell if the following code is a bug, or if I need to throw in a cast somewhere. Produces this: bug.d(9): function std.string.toString called with argument types: (wchar) matches both: std.string.toString(char) and: std.string.toString(creal) I'm guessing it's matching by implicit conversions, but that's just a little confusing??? -KramerYou could add these two functions to your code (or Phobos; hint, hint) char[] toString(wchar c) { wchar[] result; result.length = 1; result[0] = c; return std.utf.toUTF8(result); } char[] toString(dchar c) { dchar[] result; result.length = 1; result[0] = c; return std.utf.toUTF8(result); } -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 10/02/2006 5:36:19 PM
Feb 10 2006
On Sat, 11 Feb 2006 07:29:01 +1100, Kramer <Kramer_member pathlink.com> wrote:This also compiles. You don't have to put in a try block to catch the utf exception, but I'm not sure if this is any *better* necessarily because of the cast.It might compile but its wrong to do it this way. A wchar is two-bytes long. The resulting char[] might one or two bytes long depending on the content of 'c'. -- Derek Parnell Melbourne, Australia
Feb 10 2006
In article <op.s4r4zzwc6b8z09 ginger.vic.bigpond.net.au>, Derek Parnell says...On Sat, 11 Feb 2006 07:29:01 +1100, Kramer <Kramer_member pathlink.com> wrote:Thanks, I'll be sure not to do it this way. I'm going from memeory here, but I believe I had the -w flag thrown. Would've been nice to see a narrowing warning as I know others have asked for as well. -KramerThis also compiles. You don't have to put in a try block to catch the utf exception, but I'm not sure if this is any *better* necessarily because of the cast.It might compile but its wrong to do it this way. A wchar is two-bytes long. The resulting char[] might one or two bytes long depending on the content of 'c'. -- Derek Parnell Melbourne, Australia
Feb 13 2006