D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4853 - Problems with some dchar/dstring concats
Summary: Problems with some dchar/dstring concats
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Sean Kelly
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-11 08:41 UTC by bearophile_hugs
Modified: 2010-09-11 11:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-09-11 08:41:59 UTC
(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 bearophile_hugs 2010-09-11 11:00:25 UTC
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 bearophile_hugs 2010-09-11 11:03:53 UTC
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.