D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10315 - Conditional triple operator unifies a char and a dchar as a uint
Summary: Conditional triple operator unifies a char and a dchar as a uint
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 major
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2013-06-09 07:03 UTC by bearophile_hugs
Modified: 2020-08-09 09:16 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2013-06-09 07:03:23 UTC
void main() {
    dchar c;
    pragma(msg, typeof(true ? c : ' '));
}



DMD 2.064alpha prints:
uint

Expected:
dchar


That bad type unification causes situations like:

import std.stdio: writeln;
import std.algorithm: map;
void main() {
    "just 1256 some text"
    .map!(c => true ? c : ' ')
    .writeln;
}


That prints:

[106, 117, 115, 116, 32, 49, 50, 53, 54, 32, 115, 111, 109, 101, 32, 116, 101, 120, 116]
Comment 1 bearophile_hugs 2013-08-30 07:49:17 UTC
See also Issue 10926
Comment 2 Don 2013-09-02 01:16:27 UTC
If you have
char c;
dchar d;
I agree that (true ? d : ' ')  should be a dchar, but only because ' ' can be implicitly converted to dchar by applying value range propagation.

But (true ? d : c) should not. It's reasonable for it to be a uint. Because c might be a UTF8 code point, not a character, so casting it to a dchar would be incorrect.
Comment 3 Walter Bright 2020-08-09 09:16:43 UTC
Don is correct.