Bug 16235 – type of conditional expression (ternary operator) is widened when operands differ in constness

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-07-04T18:59:54Z
Last change time
2024-12-13T18:48:50Z
Assigned to
No Owner
Creator
ag0aep6g
Moved to GitHub: dmd#19154 →

Comments

Comment #0 by ag0aep6g — 2016-07-04T18:59:54Z
These pass: ---- static assert(is(typeof(true ? int.init : int.init) == int)); static assert(is(typeof(true ? int.init : const(int).init) == int)); static assert(is(typeof(true ? byte.init : byte.init) == byte)); ---- This one fails but should pass: ---- static assert(is(typeof(true ? byte.init : const(byte).init) == byte)); ---- This makes CommonType!(byte, const byte) evaluate to int. And that makes this little program surprisingly fail compilation: ---- void main() { import std.range: chain; ubyte[] a = [1, 2]; const(ubyte)[] b = [3, 4]; ubyte f = chain(a, b).front; /* Error: cannot implicitly convert expression (chain(a, b).front()) of type int to ubyte */ } ----
Comment #1 by john.loughran.colvin — 2017-07-05T11:31:13Z
Upping the severity of this because it's such a basic thing. Especially painful when you've swapped to ubyte[] due to frustrations with autodecoding and are then faced by yet another problem.
Comment #2 by john.loughran.colvin — 2017-07-05T13:50:03Z
Comment #3 by razvan.nitu1305 — 2022-07-25T11:42:20Z
*** Issue 23268 has been marked as a duplicate of this issue. ***
Comment #4 by robert.schadek — 2024-12-13T18:48:50Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19154 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB