Make sure return is not an error.

This commit is contained in:
Stephen Chung 2020-03-17 16:52:06 +08:00
parent b26ca753c2
commit d2951bfb6b

View File

@ -217,23 +217,19 @@ impl<'e> Engine<'e> {
Ok(result)
}
match eval_ast_internal(self, scope, ast) {
Err(EvalAltResult::Return(out, pos)) => out.downcast::<T>().map(|v| *v).map_err(|a| {
EvalAltResult::ErrorMismatchOutputType(
self.map_type_name((*a).type_name()).to_string(),
pos,
)
}),
Ok(out) => out.downcast::<T>().map(|v| *v).map_err(|a| {
EvalAltResult::ErrorMismatchOutputType(
self.map_type_name((*a).type_name()).to_string(),
Position::eof(),
)
}),
Err(err) => Err(err),
}
eval_ast_internal(self, scope, ast)
.or_else(|err| match err {
EvalAltResult::Return(out, _) => Ok(out),
_ => Err(err),
})
.and_then(|out| {
out.downcast::<T>().map(|v| *v).map_err(|a| {
EvalAltResult::ErrorMismatchOutputType(
self.map_type_name((*a).type_name()).to_string(),
Position::eof(),
)
})
})
}
/// Evaluate a file, but throw away the result and only return error (if any).
@ -333,7 +329,10 @@ impl<'e> Engine<'e> {
self.clear_functions();
}
result
result.or_else(|err| match err {
EvalAltResult::Return(_, _) => Ok(()),
_ => Err(err),
})
}
/// Load a list of functions into the Engine.