From 9b8afd1dbb41cba16147d3c9412ef8fcd8dbee9c Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 21 Dec 2019 07:51:19 +0100 Subject: [PATCH] Fix #12785 (#12943) * Fix #12785 and add test * better variable name --- compiler/ccgstmts.nim | 4 ++++ tests/casestmt/t12785.nim | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/casestmt/t12785.nim diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 34fb06af8f..7473e45a69 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -492,6 +492,10 @@ iterator fieldValuePairs(n: PNode): tuple[memberSym, valueSym: PNode] = proc genComputedGoto(p: BProc; n: PNode) = # first pass: Generate array of computed labels: + + # flatten the loop body because otherwise let and var sections + # wrapped inside stmt lists by inject destructors won't be recognised + let n = n.flattenStmts() var casePos = -1 var arraySize: int for i in 0..