diff --git a/src/eval/chaining.rs b/src/eval/chaining.rs index c681ce5a..a9a34adf 100644 --- a/src/eval/chaining.rs +++ b/src/eval/chaining.rs @@ -673,7 +673,7 @@ impl Engine { self.inc_operations(&mut global.num_operations, *var_pos)?; let (mut target, _) = - self.search_namespace(scope, global, state, lib, this_ptr, lhs)?; + self.search_namespace(scope, global, state, lib, this_ptr, lhs, level)?; let obj_ptr = &mut target; let root = (x.2.as_str(), *var_pos); diff --git a/src/eval/expr.rs b/src/eval/expr.rs index dcbb830b..9793bf0c 100644 --- a/src/eval/expr.rs +++ b/src/eval/expr.rs @@ -50,15 +50,18 @@ impl Engine { lib: &[&Module], this_ptr: &'s mut Option<&mut Dynamic>, expr: &Expr, + level: usize, ) -> RhaiResultOf<(Target<'s>, Position)> { match expr { Expr::Variable(Some(_), _, _) => { - self.search_scope_only(scope, global, state, lib, this_ptr, expr) + self.search_scope_only(scope, global, state, lib, this_ptr, expr, level) } Expr::Variable(None, _var_pos, v) => match v.as_ref() { // Normal variable access #[cfg(not(feature = "no_module"))] - (_, None, _) => self.search_scope_only(scope, global, state, lib, this_ptr, expr), + (_, None, _) => { + self.search_scope_only(scope, global, state, lib, this_ptr, expr, level) + } #[cfg(feature = "no_module")] (_, (), _) => self.search_scope_only(scope, global, state, lib, this_ptr, expr), @@ -136,6 +139,7 @@ impl Engine { lib: &[&Module], this_ptr: &'s mut Option<&mut Dynamic>, expr: &Expr, + level: usize, ) -> RhaiResultOf<(Target<'s>, Position)> { // Make sure that the pointer indirection is taken only when absolutely necessary. @@ -163,7 +167,7 @@ impl Engine { state, lib, this_ptr, - level: 0, + level, }; match resolve_var( expr.get_variable_name(true).expect("`Expr::Variable`"), @@ -297,7 +301,7 @@ impl Engine { .cloned() .ok_or_else(|| ERR::ErrorUnboundThis(*var_pos).into()) } else { - self.search_namespace(scope, global, state, lib, this_ptr, expr) + self.search_namespace(scope, global, state, lib, this_ptr, expr, level) .map(|(val, _)| val.take_or_clone()) }; } diff --git a/src/func/call.rs b/src/func/call.rs index 292bd33f..e688178a 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -1230,7 +1230,7 @@ impl Engine { })?; let (mut target, _pos) = - self.search_namespace(scope, global, state, lib, this_ptr, first_expr)?; + self.search_namespace(scope, global, state, lib, this_ptr, first_expr, level)?; if target.as_ref().is_read_only() { target = target.into_owned(); @@ -1316,8 +1316,9 @@ impl Engine { })?; // Get target reference to first argument + let first_arg = &args_expr[0]; let (target, _pos) = - self.search_scope_only(scope, global, state, lib, this_ptr, &args_expr[0])?; + self.search_scope_only(scope, global, state, lib, this_ptr, first_arg, level)?; #[cfg(not(feature = "unchecked"))] self.inc_operations(&mut global.num_operations, _pos)?;