diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index f9654bb1fb..7fd4ce22db 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -404,6 +404,9 @@ proc genComputedGoto(p: BProc; n: PNode) = localError(p.config, it.info, "case statement must be exhaustive for computed goto"); return casePos = i + if enumHasHoles(it.sons[0].typ): + localError(p.config, it.info, + "case statement cannot work on enums with holes for computed goto"); return let aSize = lengthOrd(p.config, it.sons[0].typ) if aSize > 10_000: localError(p.config, it.info, diff --git a/tests/casestmt/t7699.nim b/tests/casestmt/t7699.nim new file mode 100644 index 0000000000..ea08388eb7 --- /dev/null +++ b/tests/casestmt/t7699.nim @@ -0,0 +1,15 @@ +discard """ + line: 13 + errormsg: "case statement cannot work on enums with holes for computed goto" +""" + +type + X = enum + A = 0, B = 100 + +var z = A +while true: + {.computedGoto.} + case z + of A: discard + of B: discard