Bug 10315 – Conditional triple operator unifies a char and a dchar as a uint

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-06-09T07:03:23Z
Last change time
2020-08-09T09:16:43Z
Keywords
wrong-code
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-06-09T07:03:23Z
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 by bearophile_hugs — 2013-08-30T07:49:17Z
See also Issue 10926
Comment #2 by clugdbug — 2013-09-02T01:16:27Z
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 by bugzilla — 2020-08-09T09:16:43Z
Don is correct.