diff --git a/src/Vm/InstructionExecutor.cs b/src/Vm/InstructionExecutor.cs index 5dbc923..3b35757 100644 --- a/src/Vm/InstructionExecutor.cs +++ b/src/Vm/InstructionExecutor.cs @@ -655,14 +655,19 @@ private void UnpackUpper(byte count) private void ExitBlock(byte popCount) { - if (_stack.Count == 1) + if (_stack.Count == popCount) + { + while (_stack.Any()) + Pop(); + return; + } - var returnValue = _stack.Pop(); + var returnValue = _stack.PopObject() as RuntimeObject; for (byte i = 0; i < popCount; i++) Pop(); - _stack.Push(returnValue); + _stack.Push(returnValue ?? RuntimeNil.Value); } private void Ret()