Class with type_conversion from int and "==" operator causes switch statement to compare destroyed objects

I added a Function_Push_Pop to save the match_value and the value from evaluating the case statement. This makes the code look like Fold_Right_Binary_Operator_AST_Node::do_oper, which does not have the same defect behavior.
This commit is contained in:
dinghram 2018-03-05 11:04:59 -07:00
parent ef47b4582e
commit 235af9bf33

View File

@ -1027,9 +1027,19 @@ namespace chaiscript
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.
try {
if (hasMatched || boxed_cast<bool>(t_ss->call_function("==", m_loc, {match_value, this->children[currentCase]->children[0]->eval(t_ss)}, t_ss.conversions()))) {
if (hasMatched) {
this->children[currentCase]->eval(t_ss);
hasMatched = true;
}
else {
auto case_value = this->children[currentCase]->children[0]->eval(t_ss);
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
fpp.save_params({match_value, case_value});
if (boxed_cast<bool>(t_ss->call_function("==", m_loc, {match_value, case_value}, t_ss.conversions()))) {
this->children[currentCase]->eval(t_ss);
hasMatched = true;
}
}
}
catch (const exception::bad_boxed_cast &) {