Support default
case in the non-last position
This commit is contained in:
parent
64dd349e32
commit
84e2d449b9
@ -950,7 +950,7 @@ namespace chaiscript
|
||||
}
|
||||
else if (this->children[currentCase]->identifier == AST_Node_Type::Default) {
|
||||
this->children[currentCase]->eval(t_ss);
|
||||
breaking = true;
|
||||
hasMatched = true;
|
||||
}
|
||||
}
|
||||
catch (detail::Break_Loop &) {
|
||||
|
@ -1807,6 +1807,8 @@ namespace chaiscript
|
||||
|
||||
build_match<eval::Case_AST_Node>(prev_stack_top);
|
||||
} else if (Keyword("default")) {
|
||||
retval = true;
|
||||
|
||||
while (Eol()) {}
|
||||
|
||||
if (!Block()) {
|
||||
|
18
unittests/switch_default_2.chai
Normal file
18
unittests/switch_default_2.chai
Normal file
@ -0,0 +1,18 @@
|
||||
var total = 0;
|
||||
|
||||
switch(2) {
|
||||
case (1) {
|
||||
total += 1;
|
||||
}
|
||||
default {
|
||||
total += 16;
|
||||
}
|
||||
case (3) {
|
||||
total += 4;
|
||||
}
|
||||
case (4) {
|
||||
total += 8;
|
||||
}
|
||||
}
|
||||
|
||||
assert_equal(total, 28)
|
Loading…
x
Reference in New Issue
Block a user