Bug 23172 – [REG2.100] Wrong cast inserted for ternary operator and non-int enums
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-06-07T22:32:53Z
Last change time
2022-07-09T16:32:05Z
Keywords
industry, pull, rejects-valid
Assigned to
No Owner
Creator
johanengelen
Comments
Comment #0 by johanengelen — 2022-06-07T22:32:53Z
Testcase:
```
enum E : ubyte { // `ubyte` is needed to trigger the bug
A,
B,
}
struct S {
E e;
}
void compiles(bool b, S s) {
E e = b ? E.A : s.e;
}
void errors(bool b, const ref S s) {
E e = b ? E.A : s.e;
}
```
Errors with: <source>(15): Error: cannot implicitly convert expression `b ? 0 : cast(int)s.e` of type `int` to `E`
Fails with LDC 1.30.0-beta1 (dlang 2.100.0), compiles succesfully with LDC 1.29 (dlang 2.099).
Comment #1 by b2.temp — 2022-06-15T09:29:04Z
*** Issue 23188 has been marked as a duplicate of this issue. ***
Comment #2 by dkorpel — 2022-06-15T18:50:00Z
Introduced by https://github.com/dlang/dmd/pull/13961
```
digger: 220aedbd1c5c102d26967be5706d5fe8f689a56c is the first bad commit
commit 220aedbd1c5c102d26967be5706d5fe8f689a56c
Author: Boris Carvajal <[email protected]>
Date: Thu Apr 7 04:40:23 2022 -0400
dmd: Fix Issue 22988 - no short-circuiting when constant folding ternary operator
```
Comment #3 by dlang-bot — 2022-06-17T09:47:12Z
@BorisCarvajal created dlang/dmd pull request #14226 "Fix Issue 23172 - [REG2.100] Wrong cast inserted for ternary operator and non-int enums" fixing this issue:
- Fix Issue 23172 - [REG2.100] Wrong cast inserted for ternary operator and non-int enums
https://github.com/dlang/dmd/pull/14226
Comment #4 by dlang-bot — 2022-06-18T09:46:43Z
dlang/dmd pull request #14226 "Fix Issue 23172 - [REG2.100] Wrong cast inserted for ternary operator and non-int enums" was merged into stable:
- 7b2bfe66b4e1c40a8a103721828faff14efc294e by Boris Carvajal:
Fix Issue 23172 - [REG2.100] Wrong cast inserted for ternary operator and non-int enums
https://github.com/dlang/dmd/pull/14226
Comment #5 by dlang-bot — 2022-07-09T16:32:05Z
dlang/dmd pull request #14280 "merge stable" was merged into master:
- 10f612d3bce5b560ccef7098a089df4ceeb2c006 by Boris Carvajal:
Fix Issue 23172 - [REG2.100] Wrong cast inserted for ternary operator and non-int enums
https://github.com/dlang/dmd/pull/14280