Skip to content

Commit 34443c6

Browse files
dkorpelthewilsonator
authored andcommitted
Fix #23185 - ICE on final switch error at CTFE
1 parent 69a4014 commit 34443c6

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

compiler/src/dmd/dinterpret.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,11 @@ Expression interpretStatement(UnionExp* pue, Statement s, InterState* istate)
12861286
if (!scase)
12871287
{
12881288
if (!s.hasDefault)
1289+
{
12891290
error(s.loc, "no `default` or `case` for `%s` in `switch` statement", econdition.toErrMsg());
1291+
result = CTFEExp.cantexp;
1292+
return;
1293+
}
12901294
scase = s.sdefault;
12911295
}
12921296

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://github.com/dlang/dmd/issues/23185
2+
3+
/*
4+
TEST_OUTPUT:
5+
---
6+
fail_compilation/test23185.d(11): Error: no `default` or `case` for `3` in `switch` statement
7+
fail_compilation/test23185.d(15): called from here: `(*function () pure nothrow @nogc @safe => 0)()`
8+
---
9+
*/
10+
enum x = () {
11+
final switch (3) {
12+
case 1: break;
13+
}
14+
return 0;
15+
} ();

0 commit comments

Comments
 (0)