Flatten function call arguments.

This commit is contained in:
Stephen Chung 2021-03-20 23:57:43 +08:00
parent aa0594210c
commit 297a539528

View File

@ -102,21 +102,18 @@ pub fn ensure_no_data_race(
args: &FnCallArgs, args: &FnCallArgs,
is_ref: bool, is_ref: bool,
) -> Result<(), Box<EvalAltResult>> { ) -> Result<(), Box<EvalAltResult>> {
if cfg!(not(feature = "no_closure")) { #[cfg(not(feature = "no_closure"))]
let skip = if is_ref { 1 } else { 0 }; if let Some((n, _)) = args
.iter()
if let Some((n, _)) = args .enumerate()
.iter() .skip(if is_ref { 1 } else { 0 })
.skip(skip) .find(|(_, a)| a.is_locked())
.enumerate() {
.find(|(_, a)| a.is_locked()) return EvalAltResult::ErrorDataRace(
{ format!("argument #{} of function '{}'", n + 1, fn_name),
return EvalAltResult::ErrorDataRace( Position::NONE,
format!("argument #{} of function '{}'", n + 1 + skip, fn_name), )
Position::NONE, .into();
)
.into();
}
} }
Ok(()) Ok(())
@ -636,9 +633,8 @@ impl Engine {
_level: usize, _level: usize,
) -> Result<(Dynamic, bool), Box<EvalAltResult>> { ) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
// Check for data race. // Check for data race.
if cfg!(not(feature = "no_closure")) { #[cfg(not(feature = "no_closure"))]
ensure_no_data_race(fn_name, args, is_ref)?; ensure_no_data_race(fn_name, args, is_ref)?;
}
// These may be redirected from method style calls. // These may be redirected from method style calls.
match fn_name { match fn_name {
@ -1259,7 +1255,10 @@ impl Engine {
arg_values = args_expr arg_values = args_expr
.iter() .iter()
.skip(1) .skip(1)
.map(|expr| self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)) .map(|expr| {
self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)
.map(Dynamic::flatten)
})
.collect::<Result<_, _>>()?; .collect::<Result<_, _>>()?;
let (mut target, pos) = let (mut target, pos) =
@ -1285,7 +1284,10 @@ impl Engine {
// func(..., ...) // func(..., ...)
arg_values = args_expr arg_values = args_expr
.iter() .iter()
.map(|expr| self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)) .map(|expr| {
self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)
.map(Dynamic::flatten)
})
.collect::<Result<_, _>>()?; .collect::<Result<_, _>>()?;
args = curry.iter_mut().chain(arg_values.iter_mut()).collect(); args = curry.iter_mut().chain(arg_values.iter_mut()).collect();
@ -1340,6 +1342,7 @@ impl Engine {
Ok(Default::default()) Ok(Default::default())
} else { } else {
self.eval_expr(scope, mods, state, lib, this_ptr, expr, level) self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)
.map(Dynamic::flatten)
} }
}) })
.collect::<Result<_, _>>()?; .collect::<Result<_, _>>()?;
@ -1364,7 +1367,10 @@ impl Engine {
// func(..., ...) or func(mod::x, ...) // func(..., ...) or func(mod::x, ...)
arg_values = args_expr arg_values = args_expr
.iter() .iter()
.map(|expr| self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)) .map(|expr| {
self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)
.map(Dynamic::flatten)
})
.collect::<Result<_, _>>()?; .collect::<Result<_, _>>()?;
args = arg_values.iter_mut().collect(); args = arg_values.iter_mut().collect();