diff --git a/RELEASES.md b/RELEASES.md index 394e5e80..4649f7a5 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -11,13 +11,13 @@ Breaking changes * `Module::iter_script_fn_info` is removed and merged into `Module::iter_script_fn`. * The `merge_namespaces` parameter to `Module::eval_ast_as_new` is removed and now defaults to `true`. * `GlobalFileModuleResolver` is removed because its performance gain over the `FileModuleResolver` is no longer very significant. -* `EvalAltResult::ErrorCharMismatch` is renamed to `EvalAltResult::ErrorMismatchDataType`. +* The following `EvalAltResult` variants are removed and merged into `EvalAltResult::ErrorMismatchDataType`: `ErrorCharMismatch`, `ErrorNumericIndexExpr`, `ErrorStringIndexExpr`, `ErrorImportExpr`, `ErrorLogicGuard`, `ErrorBooleanArgMismatch` New features ------------ * `OptimizationLevel::Simple` now eagerly evaluates built-in binary operators of primary types (if not overloaded). -* Added `is_def_var()` to detect if variable is defined and `is_def_fn()` to detect if script function is defined. +* Added `is_def_var()` to detect if variable is defined, and `is_def_fn()` to detect if script function is defined. * Added `Module::get_script_fn` to get a scripted function in a module, if any, based on name and number of parameters. diff --git a/src/engine.rs b/src/engine.rs index 231ceb1c..d4c326ce 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -7,7 +7,7 @@ use crate::fn_native::{Callback, FnPtr}; use crate::module::{Module, ModuleRef}; use crate::optimize::OptimizationLevel; use crate::packages::{Package, PackagesCollection, StandardPackage}; -use crate::parser::{Expr, ReturnType, Stmt}; +use crate::parser::{Expr, ReturnType, Stmt, INT}; use crate::r#unsafe::unsafe_cast_var_name_to_lifetime; use crate::result::EvalAltResult; use crate::scope::{EntryType as ScopeEntryType, Scope}; @@ -33,6 +33,7 @@ use crate::utils::ImmutableString; use crate::any::DynamicWriteLock; use crate::stdlib::{ + any::type_name, boxed::Box, collections::{HashMap, HashSet}, fmt, format, @@ -243,7 +244,7 @@ impl Target<'_> { #[cfg(not(feature = "no_index"))] Self::StringChar(_, _, ch) => { let new_val = ch.clone(); - self.set_value(new_val, Position::none(), Position::none()) + self.set_value((new_val, Position::none()), Position::none()) .unwrap(); } } @@ -251,15 +252,14 @@ impl Target<'_> { /// Update the value of the `Target`. pub fn set_value( &mut self, - new_val: Dynamic, + new_val: (Dynamic, Position), target_pos: Position, - new_pos: Position, ) -> Result<(), Box> { match self { - Self::Ref(r) => **r = new_val, + Self::Ref(r) => **r = new_val.0, #[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_object"))] - Self::LockGuard((r, _)) => **r = new_val, + Self::LockGuard((r, _)) => **r = new_val.0, Self::Value(_) => { return EvalAltResult::ErrorAssignmentToUnknownLHS(target_pos).into(); } @@ -268,11 +268,11 @@ impl Target<'_> { let mut s = string.write_lock::().unwrap(); // Replace the character at the specified index position - let new_ch = new_val.as_char().map_err(|err| { + let new_ch = new_val.0.as_char().map_err(|err| { Box::new(EvalAltResult::ErrorMismatchDataType( err.to_string(), "char".to_string(), - new_pos, + new_val.1, )) })?; @@ -713,8 +713,7 @@ impl Engine { idx_values: &mut StaticVec, chain_type: ChainType, level: usize, - new_val: Option, - new_pos: Position, + new_val: Option<(Dynamic, Position)>, ) -> Result<(Dynamic, bool), Box> { if chain_type == ChainType::None { panic!(); @@ -747,7 +746,7 @@ impl Engine { self.eval_dot_index_chain_helper( state, lib, this_ptr, obj_ptr, expr, idx_values, next_chain, level, - new_val, new_pos, + new_val, ) .map_err(|err| err.new_position(*pos)) } @@ -761,7 +760,7 @@ impl Engine { { // Indexed value is a reference - update directly Ok(ref mut obj_ptr) => { - obj_ptr.set_value(new_val.unwrap(), rhs.position(), new_pos)?; + obj_ptr.set_value(new_val.unwrap(), rhs.position())?; None } Err(err) => match *err { @@ -777,7 +776,7 @@ impl Engine { if let Some(mut new_val) = _call_setter { let val = target.as_mut(); let val_type_name = val.type_name(); - let args = &mut [val, &mut idx_val2, &mut new_val]; + let args = &mut [val, &mut idx_val2, &mut new_val.0]; self.exec_fn_call( state, lib, FN_IDX_SET, 0, args, is_ref, true, false, None, &None, @@ -825,7 +824,7 @@ impl Engine { let mut val = self .get_indexed_mut(state, lib, target, index, *pos, true, false, level)?; - val.set_value(new_val.unwrap(), rhs.position(), new_pos)?; + val.set_value(new_val.unwrap(), rhs.position())?; Ok((Default::default(), true)) } // {xxx:map}.id @@ -842,7 +841,7 @@ impl Engine { Expr::Property(x) if new_val.is_some() => { let ((_, _, setter), pos) = x.as_ref(); let mut new_val = new_val; - let mut args = [target.as_mut(), new_val.as_mut().unwrap()]; + let mut args = [target.as_mut(), &mut new_val.as_mut().unwrap().0]; self.exec_fn_call( state, lib, setter, 0, &mut args, is_ref, true, false, None, &None, level, @@ -893,7 +892,7 @@ impl Engine { self.eval_dot_index_chain_helper( state, lib, this_ptr, &mut val, expr, idx_values, next_chain, level, - new_val, new_pos, + new_val, ) .map_err(|err| err.new_position(*pos)) } @@ -927,7 +926,6 @@ impl Engine { next_chain, level, new_val, - new_pos, ) .map_err(|err| err.new_position(*pos))?; @@ -967,7 +965,7 @@ impl Engine { self.eval_dot_index_chain_helper( state, lib, this_ptr, target, expr, idx_values, next_chain, - level, new_val, new_pos, + level, new_val, ) .map_err(|err| err.new_position(*pos)) } @@ -997,8 +995,7 @@ impl Engine { this_ptr: &mut Option<&mut Dynamic>, expr: &Expr, level: usize, - new_val: Option, - new_pos: Position, + new_val: Option<(Dynamic, Position)>, ) -> Result> { let ((dot_lhs, dot_rhs, op_pos), chain_type) = match expr { Expr::Index(x) => (x.as_ref(), ChainType::Index), @@ -1034,8 +1031,7 @@ impl Engine { let obj_ptr = &mut target.into(); self.eval_dot_index_chain_helper( - state, lib, &mut None, obj_ptr, dot_rhs, idx_values, chain_type, level, - new_val, new_pos, + state, lib, &mut None, obj_ptr, dot_rhs, idx_values, chain_type, level, new_val, ) .map(|(v, _)| v) .map_err(|err| err.new_position(*op_pos)) @@ -1050,7 +1046,6 @@ impl Engine { let obj_ptr = &mut val.into(); self.eval_dot_index_chain_helper( state, lib, this_ptr, obj_ptr, dot_rhs, idx_values, chain_type, level, new_val, - new_pos, ) .map(|(v, _)| v) .map_err(|err| err.new_position(*op_pos)) @@ -1159,7 +1154,7 @@ impl Engine { // val_array[idx] let index = idx .as_int() - .map_err(|_| EvalAltResult::ErrorNumericIndexExpr(idx_pos))?; + .map_err(|err| self.make_type_mismatch_err::(err, idx_pos))?; let arr_len = arr.len(); @@ -1178,15 +1173,15 @@ impl Engine { Dynamic(Union::Map(map)) => { // val_map[idx] Ok(if _create { - let index = idx - .take_immutable_string() - .map_err(|_| EvalAltResult::ErrorStringIndexExpr(idx_pos))?; + let index = idx.take_immutable_string().map_err(|err| { + self.make_type_mismatch_err::(err, idx_pos) + })?; map.entry(index).or_insert_with(Default::default).into() } else { - let index = idx - .read_lock::() - .ok_or_else(|| EvalAltResult::ErrorStringIndexExpr(idx_pos))?; + let index = idx.read_lock::().ok_or_else(|| { + self.make_type_mismatch_err::("", idx_pos) + })?; map.get_mut(&*index) .map(Target::from) @@ -1200,7 +1195,7 @@ impl Engine { let chars_len = s.chars().count(); let index = idx .as_int() - .map_err(|_| EvalAltResult::ErrorNumericIndexExpr(idx_pos))?; + .map_err(|err| self.make_type_mismatch_err::(err, idx_pos))?; if index >= 0 { let offset = index as usize; @@ -1438,9 +1433,9 @@ impl Engine { let mut rhs_val = self.eval_expr(scope, mods, state, lib, this_ptr, rhs_expr, level)?; - let (_new_val, _new_pos) = if op.is_empty() { + let _new_val = if op.is_empty() { // Normal assignment - (Some(rhs_val), rhs_expr.position()) + Some((rhs_val, rhs_expr.position())) } else { // Op-assignment - always map to `lhs = lhs op rhs` let op = &op[..op.len() - 1]; // extract operator without = @@ -1456,7 +1451,7 @@ impl Engine { .map(|(v, _)| v) .map_err(|err| err.new_position(*op_pos))?; - (Some(result), rhs_expr.position()) + Some((result, rhs_expr.position())) }; match lhs_expr { @@ -1466,7 +1461,7 @@ impl Engine { #[cfg(not(feature = "no_index"))] Expr::Index(_) => { self.eval_dot_index_chain( - scope, mods, state, lib, this_ptr, lhs_expr, level, _new_val, _new_pos, + scope, mods, state, lib, this_ptr, lhs_expr, level, _new_val, )?; Ok(Default::default()) } @@ -1474,7 +1469,7 @@ impl Engine { #[cfg(not(feature = "no_object"))] Expr::Dot(_) => { self.eval_dot_index_chain( - scope, mods, state, lib, this_ptr, lhs_expr, level, _new_val, _new_pos, + scope, mods, state, lib, this_ptr, lhs_expr, level, _new_val, )?; Ok(Default::default()) } @@ -1491,31 +1486,15 @@ impl Engine { // lhs[idx_expr] #[cfg(not(feature = "no_index"))] - Expr::Index(_) => self.eval_dot_index_chain( - scope, - mods, - state, - lib, - this_ptr, - expr, - level, - None, - Position::none(), - ), + Expr::Index(_) => { + self.eval_dot_index_chain(scope, mods, state, lib, this_ptr, expr, level, None) + } // lhs.dot_rhs #[cfg(not(feature = "no_object"))] - Expr::Dot(_) => self.eval_dot_index_chain( - scope, - mods, - state, - lib, - this_ptr, - expr, - level, - None, - Position::none(), - ), + Expr::Dot(_) => { + self.eval_dot_index_chain(scope, mods, state, lib, this_ptr, expr, level, None) + } #[cfg(not(feature = "no_index"))] Expr::Array(x) => Ok(Dynamic(Union::Array(Box::new( @@ -1562,16 +1541,12 @@ impl Engine { Ok((self .eval_expr(scope, mods, state, lib, this_ptr, lhs, level)? .as_bool() - .map_err(|_| { - EvalAltResult::ErrorBooleanArgMismatch("AND".into(), lhs.position()) - })? + .map_err(|err| self.make_type_mismatch_err::(err, lhs.position()))? && // Short-circuit using && self .eval_expr(scope, mods, state, lib, this_ptr, rhs, level)? .as_bool() - .map_err(|_| { - EvalAltResult::ErrorBooleanArgMismatch("AND".into(), rhs.position()) - })?) + .map_err(|err| self.make_type_mismatch_err::(err, rhs.position()))?) .into()) } @@ -1580,16 +1555,12 @@ impl Engine { Ok((self .eval_expr(scope, mods, state, lib, this_ptr, lhs, level)? .as_bool() - .map_err(|_| { - EvalAltResult::ErrorBooleanArgMismatch("OR".into(), lhs.position()) - })? + .map_err(|err| self.make_type_mismatch_err::(err, lhs.position()))? || // Short-circuit using || self .eval_expr(scope, mods, state, lib, this_ptr, rhs, level)? .as_bool() - .map_err(|_| { - EvalAltResult::ErrorBooleanArgMismatch("OR".into(), rhs.position()) - })?) + .map_err(|err| self.make_type_mismatch_err::(err, rhs.position()))?) .into()) } @@ -1671,7 +1642,7 @@ impl Engine { self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)? .as_bool() - .map_err(|_| EvalAltResult::ErrorLogicGuard(expr.position()).into()) + .map_err(|err| self.make_type_mismatch_err::(err, expr.position())) .and_then(|guard_val| { if guard_val { self.eval_stmt(scope, mods, state, lib, this_ptr, if_block, level) @@ -1704,7 +1675,9 @@ impl Engine { } } Ok(false) => return Ok(Default::default()), - Err(_) => return EvalAltResult::ErrorLogicGuard(expr.position()).into(), + Err(err) => { + return Err(self.make_type_mismatch_err::(err, expr.position())) + } } }, @@ -1873,7 +1846,7 @@ impl Engine { ) } } else { - EvalAltResult::ErrorImportExpr(expr.position()).into() + Err(self.make_type_mismatch_err::("", expr.position())) } } @@ -2068,4 +2041,14 @@ impl Engine { .and_then(|t| t.get(name).map(String::as_str)) .unwrap_or_else(|| map_std_type_name(name)) } + + /// Make a Box>. + pub fn make_type_mismatch_err(&self, typ: &str, pos: Position) -> Box { + EvalAltResult::ErrorMismatchDataType( + typ.into(), + self.map_type_name(type_name::()).into(), + pos, + ) + .into() + } } diff --git a/src/fn_call.rs b/src/fn_call.rs index 473a948d..557a3fd2 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -844,15 +844,6 @@ impl Engine { capture: bool, level: usize, ) -> Result> { - fn make_type_err(engine: &Engine, typ: &str, pos: Position) -> Box { - EvalAltResult::ErrorMismatchDataType( - typ.into(), - engine.map_type_name(type_name::()).into(), - pos, - ) - .into() - } - // Handle Fn() if name == KEYWORD_FN_PTR && args_expr.len() == 1 { let hash_fn = calc_fn_hash(empty(), name, 1, once(TypeId::of::())); @@ -864,7 +855,9 @@ impl Engine { return arg_value .take_immutable_string() - .map_err(|typ| make_type_err::(self, typ, expr.position())) + .map_err(|typ| { + self.make_type_mismatch_err::(typ, expr.position()) + }) .and_then(|s| FnPtr::try_from(s)) .map(Into::::into) .map_err(|err| err.new_position(expr.position())); @@ -877,8 +870,7 @@ impl Engine { let arg_value = self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)?; if !arg_value.is::() { - return Err(make_type_err::( - self, + return Err(self.make_type_mismatch_err::( self.map_type_name(arg_value.type_name()), expr.position(), )); @@ -932,8 +924,7 @@ impl Engine { // Recalculate hash hash_script = calc_fn_hash(empty(), name, curry.len() + args_expr.len(), empty()); } else { - return Err(make_type_err::( - self, + return Err(self.make_type_mismatch_err::( self.map_type_name(arg_value.type_name()), expr.position(), )); @@ -947,9 +938,9 @@ impl Engine { if !self.has_override(lib, hash_fn, hash_script, pub_only) { let expr = args_expr.get(0).unwrap(); let arg_value = self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)?; - let var_name = arg_value - .as_str() - .map_err(|err| make_type_err::(self, err, expr.position()))?; + let var_name = arg_value.as_str().map_err(|err| { + self.make_type_mismatch_err::(err, expr.position()) + })?; if var_name.is_empty() { return Ok(false.into()); } else { @@ -979,11 +970,11 @@ impl Engine { self.eval_expr(scope, mods, state, lib, this_ptr, num_params_expr, level)?; let fn_name = arg0_value.as_str().map_err(|err| { - make_type_err::(self, err, fn_name_expr.position()) + self.make_type_mismatch_err::(err, fn_name_expr.position()) + })?; + let num_params = arg1_value.as_int().map_err(|err| { + self.make_type_mismatch_err::(err, num_params_expr.position()) })?; - let num_params = arg1_value - .as_int() - .map_err(|err| make_type_err::(self, err, num_params_expr.position()))?; if fn_name.is_empty() || num_params < 0 { return Ok(false.into()); @@ -1003,9 +994,9 @@ impl Engine { let prev_len = scope.len(); let expr = args_expr.get(0).unwrap(); let arg_value = self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)?; - let script = arg_value - .as_str() - .map_err(|typ| make_type_err::(self, typ, expr.position()))?; + let script = arg_value.as_str().map_err(|typ| { + self.make_type_mismatch_err::(typ, expr.position()) + })?; let result = if !script.is_empty() { self.eval_script_expr(scope, mods, state, lib, script, level + 1) .map_err(|err| err.new_position(expr.position())) diff --git a/src/result.rs b/src/result.rs index 8ad32926..b5a359be 100644 --- a/src/result.rs +++ b/src/result.rs @@ -34,21 +34,26 @@ pub enum EvalAltResult { #[cfg(not(target_arch = "wasm32"))] ErrorReadingScriptFile(PathBuf, Position, std::io::Error), - /// Call to an unknown function. Wrapped value is the signature of the function. + /// Usage of an unknown variable. Wrapped value is the variable name. + ErrorVariableNotFound(String, Position), + /// Call to an unknown function. Wrapped value is the function signature. ErrorFunctionNotFound(String, Position), /// An error has occurred inside a called function. - /// Wrapped values are the name of the function and the interior error. + /// Wrapped values are the function name and the interior error. ErrorInFunctionCall(String, Box, Position), + /// Usage of an unknown module. Wrapped value is the module name. + ErrorModuleNotFound(String, Position), /// An error has occurred while loading a module. - /// Wrapped value are the name of the module and the interior error. + /// Wrapped value are the module name and the interior error. ErrorInModule(String, Box, Position), /// Access to `this` that is not bound. ErrorUnboundThis(Position), - /// Non-boolean operand encountered for boolean operator. Wrapped value is the operator. - ErrorBooleanArgMismatch(String, Position), /// Data is not of the required type. /// Wrapped values are the type requested and type of the actual result. ErrorMismatchDataType(String, String, Position), + /// Returned type is not the same as the required output type. + /// Wrapped values are the type requested and type of the actual result. + ErrorMismatchOutputType(String, String, Position), /// Array access out-of-bounds. /// Wrapped values are the current number of elements in the array and the index number. ErrorArrayBounds(usize, INT, Position), @@ -56,33 +61,19 @@ pub enum EvalAltResult { /// Wrapped values are the current number of characters in the string and the index number. ErrorStringBounds(usize, INT, Position), /// Trying to index into a type that is not an array, an object map, or a string, and has no indexer function defined. + /// Wrapped value is the type name. ErrorIndexingType(String, Position), - /// Trying to index into an array or string with an index that is not `i64`. - ErrorNumericIndexExpr(Position), - /// Trying to index into a map with an index that is not `String`. - ErrorStringIndexExpr(Position), - /// Trying to import with an expression that is not `String`. - ErrorImportExpr(Position), /// Invalid arguments for `in` operator. ErrorInExpr(Position), - /// The guard expression in an `if` or `while` statement does not return a boolean value. - ErrorLogicGuard(Position), /// The `for` statement encounters a type that is not an iterator. ErrorFor(Position), - /// Usage of an unknown variable. Wrapped value is the name of the variable. - ErrorVariableNotFound(String, Position), - /// Usage of an unknown module. Wrapped value is the name of the module. - ErrorModuleNotFound(String, Position), - /// Data race detected when accessing a variable. Wrapped value is the name of the variable. + /// Data race detected when accessing a variable. Wrapped value is the variable name. ErrorDataRace(String, Position), /// Assignment to an inappropriate LHS (left-hand-side) expression. ErrorAssignmentToUnknownLHS(Position), - /// Assignment to a constant variable. + /// Assignment to a constant variable. Wrapped value is the variable name. ErrorAssignmentToConstant(String, Position), - /// Returned type is not the same as the required output type. - /// Wrapped values are the type requested and type of the actual result. - ErrorMismatchOutputType(String, String, Position), - /// Inappropriate member access. + /// Inappropriate property access. Wrapped value is the property name. ErrorDotExpr(String, Position), /// Arithmetic error encountered. Wrapped value is the error message. ErrorArithmetic(String, Position), @@ -92,7 +83,7 @@ pub enum EvalAltResult { ErrorTooManyModules(Position), /// Call stack over maximum limit. ErrorStackOverflow(Position), - /// Data value over maximum size limit. Wrapped values are the data type, maximum size and current size. + /// Data value over maximum size limit. Wrapped values are the type name, maximum size and current size. ErrorDataTooLarge(String, usize, usize, Position), /// The script is prematurely terminated. ErrorTerminated(Position), @@ -120,16 +111,10 @@ impl EvalAltResult { Self::ErrorInModule(_, _, _) => "Error in module", Self::ErrorFunctionNotFound(_, _) => "Function not found", Self::ErrorUnboundThis(_) => "'this' is not bound", - Self::ErrorBooleanArgMismatch(_, _) => "Boolean operator expects boolean operands", Self::ErrorMismatchDataType(_, _, _) => "Data type is incorrect", - Self::ErrorNumericIndexExpr(_) => { - "Indexing into an array or string expects an integer index" - } - Self::ErrorStringIndexExpr(_) => "Indexing into an object map expects a string index", Self::ErrorIndexingType(_, _) => { "Indexing can only be performed on an array, an object map, a string, or a type with an indexer function defined" } - Self::ErrorImportExpr(_) => "Importing a module expects a string path", Self::ErrorArrayBounds(_, index, _) if *index < 0 => { "Array access expects non-negative index" } @@ -140,7 +125,6 @@ impl EvalAltResult { } Self::ErrorStringBounds(0, _, _) => "Empty string has nothing to index", Self::ErrorStringBounds(_, _, _) => "String index out of bounds", - Self::ErrorLogicGuard(_) => "Boolean value expected", Self::ErrorFor(_) => "For loop expects an array, object map, or range", Self::ErrorVariableNotFound(_, _) => "Variable not found", Self::ErrorModuleNotFound(_, _) => "Module not found", @@ -198,11 +182,7 @@ impl fmt::Display for EvalAltResult { Self::ErrorDotExpr(s, _) if !s.is_empty() => write!(f, "{}", s)?, Self::ErrorIndexingType(_, _) - | Self::ErrorNumericIndexExpr(_) - | Self::ErrorStringIndexExpr(_) | Self::ErrorUnboundThis(_) - | Self::ErrorImportExpr(_) - | Self::ErrorLogicGuard(_) | Self::ErrorFor(_) | Self::ErrorAssignmentToUnknownLHS(_) | Self::ErrorInExpr(_) @@ -218,6 +198,9 @@ impl fmt::Display for EvalAltResult { Self::ErrorMismatchOutputType(r, s, _) => { write!(f, "Output type is incorrect: {} (expecting {})", r, s)? } + Self::ErrorMismatchDataType(r, s, _) if r.is_empty() => { + write!(f, "Data type is incorrect, expecting {}", s)? + } Self::ErrorMismatchDataType(r, s, _) => { write!(f, "Data type is incorrect: {} (expecting {})", r, s)? } @@ -226,9 +209,6 @@ impl fmt::Display for EvalAltResult { Self::ErrorLoopBreak(_, _) => f.write_str(desc)?, Self::Return(_, _) => f.write_str(desc)?, - Self::ErrorBooleanArgMismatch(op, _) => { - write!(f, "{} operator expects boolean operands", op)? - } Self::ErrorArrayBounds(_, index, _) if *index < 0 => { write!(f, "{}: {} < 0", desc, index)? } @@ -293,15 +273,10 @@ impl EvalAltResult { | Self::ErrorInFunctionCall(_, _, pos) | Self::ErrorInModule(_, _, pos) | Self::ErrorUnboundThis(pos) - | Self::ErrorBooleanArgMismatch(_, pos) | Self::ErrorMismatchDataType(_, _, pos) | Self::ErrorArrayBounds(_, _, pos) | Self::ErrorStringBounds(_, _, pos) | Self::ErrorIndexingType(_, pos) - | Self::ErrorNumericIndexExpr(pos) - | Self::ErrorStringIndexExpr(pos) - | Self::ErrorImportExpr(pos) - | Self::ErrorLogicGuard(pos) | Self::ErrorFor(pos) | Self::ErrorVariableNotFound(_, pos) | Self::ErrorModuleNotFound(_, pos) @@ -335,15 +310,10 @@ impl EvalAltResult { | Self::ErrorInFunctionCall(_, _, pos) | Self::ErrorInModule(_, _, pos) | Self::ErrorUnboundThis(pos) - | Self::ErrorBooleanArgMismatch(_, pos) | Self::ErrorMismatchDataType(_, _, pos) | Self::ErrorArrayBounds(_, _, pos) | Self::ErrorStringBounds(_, _, pos) | Self::ErrorIndexingType(_, pos) - | Self::ErrorNumericIndexExpr(pos) - | Self::ErrorStringIndexExpr(pos) - | Self::ErrorImportExpr(pos) - | Self::ErrorLogicGuard(pos) | Self::ErrorFor(pos) | Self::ErrorVariableNotFound(_, pos) | Self::ErrorModuleNotFound(_, pos) diff --git a/tests/syntax.rs b/tests/syntax.rs index a0cfa5b1..0f0090f9 100644 --- a/tests/syntax.rs +++ b/tests/syntax.rs @@ -35,9 +35,7 @@ fn test_custom_syntax() -> Result<(), Box> { if !engine .eval_expression_tree(context, scope, expr)? .as_bool() - .map_err(|_| { - EvalAltResult::ErrorBooleanArgMismatch("do-while".into(), expr.position()) - })? + .map_err(|err| engine.make_type_mismatch_err::(err, expr.position()))? { break; }