Can we disallow appending integer to string?

Nick Treleaven via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 20 04:05:00 PDT 2017


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 concatenation is not 
allowed:

	int n;
	string s;
	s = "" ~ n; //error
	s ~= n; // ok!

This is the same for dchar instead of int.

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.


More information about the Digitalmars-d-learn mailing list