Can we disallow appending integer to string?
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Apr 20 12:20:28 PDT 2017
On Thu, Apr 20, 2017 at 11:05:00AM +0000, 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 against things like
> this, even if we can't agree to prevent the conversion overall. It
> would be nice if we filed a bug as a rallying point for ideas on this
> issue.
+1. Recently I was bitten by the char/int overload ambiguity problem,
and it was not pretty. Well, actually, it was worse in my case because I
had overloaded char against ubyte. Basically the only way I can
disambiguate is to wrap one of them in a struct to force the compiler to
treat them differently.
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.
T
--
Gone Chopin. Bach in a minuet.
More information about the Digitalmars-d-learn
mailing list