Make sure return is not an error.

This commit is contained in:
Stephen Chung 2020-03-17 16:52:06 +08:00
parent 2f7ca3935b
commit 706e0a0c4c

View File

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