From 025db4ce3adef69dfd524a3ef504d4ad38e10ae8 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 17 May 2012 13:20:15 -0700 Subject: [PATCH] Oops. Properly handle empty switch statements. --- include/chaiscript/language/chaiscript_eval.hpp | 4 +--- unittests/switch_empty.chai | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 unittests/switch_empty.chai 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);