6 days ago
On Thu, Apr 20, 2017 at 10:39:01PM +0000, 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:
> > 
> > 	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 with this before with:
> 
> alias OpResult(string op, A, B) = typeof((){ A* a; B* b; return
> mixin("*a"~op~"*b"); }());

Yeah, wow, that is very annoying.


T

-- 
Debian GNU/Linux: Cray on your desktop.
5 days ago
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 hadn't used but I'd been assuming probably biased from C# that
str ~ i
would be equivalent to
str ~ to!string(i)
instead of
str ~ cast(char) i

Now I see the problem too...
5 days ago
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 < byte.max.

The above mismatches would presumably be handled if we disallow implicit conversion between signed/unsigned (https://issues.dlang.org/show_bug.cgi?id=12919).

> I would like to see some small changes to mitigate against things like this, even if we can't agree to prevent the conversion overall.

It seems there's a strong case for preventing the int -> dchar conversion. wchar.max == ushort.max, char.max == ubyte.max, but dchar.max < uint.max.

Converting from char types -> integers, whilst (arguably) bug prone, at least is numerically sound. So perhaps we could disallow uint -> dchar, which is unsound.
5 days ago
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 within a dchar, by the logic of this proposal, it is allowed.
Next ›   Last »
1 2