Bug 23988 – Conditional Exp does not bring enums to correct common type if one leg is const

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-06-13T08:13:52Z
Last change time
2023-06-13T12:04:33Z
Keywords
pull
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2023-06-13T08:13:52Z
Consider: enum E : ubyte { A } pragma(msg, "test1 ", typeof(1 ? E.A : E.A)); pragma(msg, "test2 ", typeof(1 ? E.A : cast(const)E.A)); which prints: test1 E test2 int when it should print: test1 E test2 const(E) The spec sez: "If either the second or third expressions are of type void, then the resulting type is void. Otherwise, the second and third expressions are implicitly converted to a common type which becomes the result type of the conditional expression." https://dlang.org/spec/expression.html#conditional_expressions Note that it doesn't exactly say what the common type is, but what the compiler is doing is not expected. But the most obvious result should be const(E).
Comment #1 by dlang-bot — 2023-06-13T08:35:02Z
@WalterBright created dlang/dmd pull request #15316 "fix Issue 23988 - Conditional Exp does not bring enums to correct com…" fixing this issue: - fix Issue 23988 - Conditional Exp does not bring enums to correct common type if one leg is const https://github.com/dlang/dmd/pull/15316
Comment #2 by dlang-bot — 2023-06-13T12:04:33Z
dlang/dmd pull request #15316 "fix Issue 23988 - Conditional Exp does not bring enums to correct com…" was merged into master: - 8e9d9db58d97d1509d9fa0cf4a2f8b0f96f86747 by Walter Bright: fix Issue 23988 - Conditional Exp does not bring enums to correct common type if one leg is const https://github.com/dlang/dmd/pull/15316