Re: Can we disallow appending integer to string?

2017-04-21 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 21 April 2017 at 08:36:12 UTC, Nick Treleaven wrote: Converting from char types -> integers, whilst (arguably) bug prone, at least is numerically sound. So perhaps we could disallow uint -> dchar, which is unsound. That is in the general case - when VRP can prove an integer fits

Re: Can we disallow appending integer to string?

2017-04-21 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 20 April 2017 at 11:05:00 UTC, Nick Treleaven wrote: On Wednesday, 19 April 2017 at 14:50:38 UTC, Stanislav Blinov wrote: Because integrals implicitly convert to characters of same width (byte -> char, short -> wchar, int -> dchar). Despite char.min > byte.min, char.max <

Re: Can we disallow appending integer to string?

2017-04-21 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 14:50:38 UTC, Stanislav Blinov wrote: On Wednesday, 19 April 2017 at 14:36:13 UTC, Nick Treleaven Why is it legal to append an integer? Because integrals implicitly convert to characters of same width (byte -> char, short -> wchar, int -> dchar). Huh... I

Re: Can we disallow appending integer to string?

2017-04-20 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 20, 2017 at 10:39:01PM +, Stanislav Blinov via Digitalmars-d-learn wrote: > On Thursday, 20 April 2017 at 19:20:28 UTC, H. S. Teoh wrote: > > > > Another pernicious thing I encountered recently, related to implicit > > conversions, is this: > > > >

Re: Can we disallow appending integer to string?

2017-04-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 20 April 2017 at 19:20:28 UTC, H. S. Teoh wrote: Another pernicious thing I encountered recently, related to implicit conversions, is this: https://issues.dlang.org/show_bug.cgi?id=17336 It drew a very enunciated "WAT?!" from me. Yeah, that one is annoying. I've dealt

Re: Can we disallow appending integer to string?

2017-04-20 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn
On 04/19/2017 01:34 PM, Jonathan M Davis via Digitalmars-d-learn wrote: Yeah, which reduces the number of casts required when doing arithmetic on characters and thus reduces bugs there, Ugh, because apparently doing arithmetic on characters is such a common, important use-case in this modern

Re: Can we disallow appending integer to string?

2017-04-20 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 20, 2017 at 11:05:00AM +, Nick Treleaven via Digitalmars-d-learn wrote: [...] > This is also a problem for overloading: > > alias foo = (char c) => 1; > alias foo = (int i) => 4; > > static assert(foo(7) == 4); // fails > > I would like to see some small changes to mitigate

Re: Can we disallow appending integer to string?

2017-04-20 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 14:50:38 UTC, Stanislav Blinov wrote: Because integrals implicitly convert to characters of same width (byte -> char, short -> wchar, int -> dchar). Despite char.min > byte.min, char.max < byte.max. Anyway, appending an integer is inconsistent because

Re: Can we disallow appending integer to string?

2017-04-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 18:40:23 UTC, H. S. Teoh wrote: A few extra keystrokes to type cast(int) or cast(char) ain't gonna kill nobody. In fact, it might even save a few people by preventing certain kinds of bugs. Yup. Not to mention one could have @property auto

Re: Can we disallow appending integer to string?

2017-04-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 19, 2017 at 05:56:18PM +, Stanislav Blinov via Digitalmars-d-learn wrote: > On Wednesday, 19 April 2017 at 17:34:01 UTC, Jonathan M Davis wrote: > > Personally, I think that we should have taken the stricter approach > > and not had integral types implicit convert to character

Re: Can we disallow appending integer to string?

2017-04-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 17:34:01 UTC, Jonathan M Davis wrote: Personally, I think that we should have taken the stricter approach and not had integral types implicit convert to character types, but from what I recall, Walter feels pretty strongly about the conversion rules being the

Re: Can we disallow appending integer to string?

2017-04-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 19, 2017 14:50:38 Stanislav Blinov via Digitalmars-d- learn wrote: > On Wednesday, 19 April 2017 at 14:36:13 UTC, Nick Treleaven wrote: > > This bug is fixed as the code no longer segfaults but throws > > instead: > > https://issues.dlang.org/show_bug.cgi?id=5995 > > > > void

Re: Can we disallow appending integer to string?

2017-04-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 19 April 2017 at 14:36:13 UTC, Nick Treleaven wrote: This bug is fixed as the code no longer segfaults but throws instead: https://issues.dlang.org/show_bug.cgi?id=5995 void main(){ string ret; int i = -1; ret ~= i; } Why is it legal to append an integer?

Can we disallow appending integer to string?

2017-04-19 Thread Nick Treleaven via Digitalmars-d-learn
This bug is fixed as the code no longer segfaults but throws instead: https://issues.dlang.org/show_bug.cgi?id=5995 void main(){ string ret; int i = -1; ret ~= i; } Why is it legal to append an integer?