Bug 21805 – Allow conditional expression in types

Status
ASSIGNED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-04-06T16:15:16Z
Last change time
2024-12-13T19:15:49Z
Assigned to
Danil Sidoruk
Creator
Bolpat
Moved to GitHub: dmd#19906 →

Comments

Comment #0 by qs.il.paperinik — 2021-04-06T16:15:16Z
Allow expr ? type1 : type2 where a type is expected. Type: + ConditionalType TypeCtors[opt] BasicType TypeSuffixes[opt] + ConditionalType: + OrOrExpression ? BasicType : ConditionalType Some small conditions don't warrant 4 (or 8) LoC for defining an alias. static if (bits > 32) { alias Word = ulong; } else { alias Word = uint; } versus alias Word = bits > 32 ? ulong : uint; Another win is you can use the conditional type without having to define an alias.
Comment #1 by qs.il.paperinik — 2021-04-06T16:39:02Z
Obvious semantics: ConditionalType. The OrOrExpression is evaluated at compile-time. If it evaluates to `true`, the Type expression results to the given BasicType, if it evaluates to `false`, it results to the ConditionalType. If the evaluation fails, it is an error.
Comment #2 by robert.schadek — 2024-12-13T19:15:49Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19906 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB