diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index cb7cd50..64524fe 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -795,7 +795,7 @@ namespace chaiscript match_value = this->children[0]->eval(t_ss); - while (!breaking) { + while (!breaking && (currentCase < this->children.size())) { try { if (this->children[currentCase]->identifier == AST_Node_Type::Case) { //This is a little odd, but because want to see both the switch and the case simultaneously, I do a downcast here. @@ -818,8 +818,6 @@ namespace chaiscript breaking = true; } ++currentCase; - if (currentCase == this->children.size()) - breaking = true; } return Boxed_Value(); } diff --git a/unittests/switch_empty.chai b/unittests/switch_empty.chai new file mode 100644 index 0000000..8d3a166 --- /dev/null +++ b/unittests/switch_empty.chai @@ -0,0 +1,4 @@ +switch(true) { } + +// We just have to get here without error for success +assert_equal(true, true);