www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10315] New: Conditional triple operator unifies a char and a dchar as a unit

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10315

           Summary: Conditional triple operator unifies a char and a dchar
                    as a unit
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2013-06-09 07:03:23 PDT ---
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]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 09 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10315



--- Comment #1 from bearophile_hugs eml.cc 2013-08-30 07:49:17 PDT ---
See also Issue 10926

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10315


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Conditional triple operator |Conditional triple operator
                   |unifies a char and a dchar  |unifies a char and a dchar
                   |as a unit                   |as a uint


--- Comment #2 from Don <clugdbug yahoo.com.au> 2013-09-02 01:16:27 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 02 2013