Can we disallow appending integer to string?

Stanislav Blinov via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 19 07:50:38 PDT 2017


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?

Because integrals implicitly convert to characters of same width 
(byte -> char, short -> wchar, int -> dchar).


More information about the Digitalmars-d-learn mailing list