diff --git a/src/compile.rs b/src/compile.rs index 26eca75..a3b7584 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -479,7 +479,9 @@ impl Compiler { self.compile_statements(body)?; - for end_label in end_labels { + // sort of "stack up" the layers of with blocks: + // with a, b: body -> start_with(a) start_with(b) body() end_with(b) end_with(a) + for end_label in end_labels.into_iter().rev() { self.emit(Instruction::PopBlock); self.emit(Instruction::EnterFinally); self.set_label(end_label);