D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12711 - Ternary operator turns a character into an integral
Summary: Ternary operator turns a character into an integral
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-06 19:22 UTC by Andrej Mitrovic
Modified: 2024-12-13 18:20 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 Andrej Mitrovic 2014-05-06 19:22:40 UTC
-----
import std.ascii;
import std.algorithm;
import std.stdio;

void main()
{
    writeln( "foo-bar-doo".map!(a => a.isAlphaNum ? a : '_') );
    writeln( "foo-bar-doo".map!(a => a.isAlphaNum ? a : cast(dchar)'_') );
}
-----

$ dmd -run test.d
> [102, 111, 111, 95, 98, 97, 114, 95, 100, 111, 111]
> foo_bar_doo

This is very ugly. I'm not sure whether it's a DMD bug or a Phobos bug though.
Comment 1 bearophile_hugs 2014-05-06 19:52:03 UTC
(In reply to Andrej Mitrovic from comment #0)

> This is very ugly. I'm not sure whether it's a DMD bug or a Phobos bug
> though.

It's an ugly dmd bug:

void main() {
    pragma(msg, typeof(true ? char('x')  : '_'));
    pragma(msg, typeof(true ? wchar('x') : '_'));
    pragma(msg, typeof(true ? dchar('x') : '_'));
}


Output:

char
int
uint


But perhaps I already reported this issue, please search it in Bugzilla.
Comment 2 Andrej Mitrovic 2014-05-06 20:57:54 UTC
Seems like a dupe or another case of https://issues.dlang.org/show_bug.cgi?id=11732
Comment 3 dlangBugzillaToGithub 2024-12-13 18:20:24 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18825

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB