Bug 4853 – Problems with some dchar/dstring concats

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-09-11T08:41:00Z
Last change time
2010-09-11T11:03:53Z
Assigned to
sean
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-09-11T08:41:59Z
(Partially found by Andrej Mitrovic) This D2 program shows something strange: void main() { string s; char c; dchar d; dstring ds; s ~= d; // OK s ~= c ~ c; // ERR s ~= "" ~ c ~ c; // OK s ~= ""d ~ d ~ d; // ERR ds ~= d ~ d; // ERR ds ~= ""d ~ d ~ d; // OK } DMD 2.048 shows: test.d(7): Error: incompatible types for ((cast(int)c) ~ (cast(int)c)): 'int' and 'int' test.d(9): Error: cannot append type immutable(dchar)[] to type string test.d(10): Error: incompatible types for ((cast(uint)d) ~ (cast(uint)d)): 'uint' and 'uint' What's the right way to append two dchar to a string? I think even this line of code may eventually become correct: string cc = 'a' ~ 'b';
Comment #1 by bearophile_hugs — 2010-09-11T11:00:25Z
Probably 'a' ~ 'b' is not allowed in D to keep (in)compatibility with C language, because it has a different meaning in C.
Comment #2 by bearophile_hugs — 2010-09-11T11:03:53Z
Given that, and given that appending a dchar to a string is allowed, but appending a dstring to a string is not allowed, there are no bugs here.