From f4949a2beb805cc5531836de3a6768eea4e00c4f Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 27 Jan 2023 22:31:14 +0800 Subject: [PATCH] Always search scope after scope is modified. --- src/eval/debugger.rs | 11 +++++++++-- src/eval/expr.rs | 11 ++++++++++- src/eval/stmt.rs | 9 ++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/eval/debugger.rs b/src/eval/debugger.rs index 1bc1a5a5..652134a3 100644 --- a/src/eval/debugger.rs +++ b/src/eval/debugger.rs @@ -505,14 +505,21 @@ impl Engine { event: DebuggerEvent, ) -> Result, Box> { if let Some(ref x) = self.debugger_interface { + let orig_scope_len = scope.len(); + let src = global.source_raw().cloned(); let src = src.as_ref().map(|s| s.as_str()); let context = EvalContext::new(self, global, caches, scope, this_ptr); let (.., ref on_debugger) = **x; - let command = on_debugger(context, event, node, src, node.position())?; + let command = on_debugger(context, event, node, src, node.position()); - match command { + if orig_scope_len != scope.len() { + // The scope is changed, always search from now on + global.always_search_scope = true; + } + + match command? { DebuggerCommand::Continue => { global.debugger_mut().status = DebuggerStatus::CONTINUE; Ok(None) diff --git a/src/eval/expr.rs b/src/eval/expr.rs index 75d9c0a5..925a8132 100644 --- a/src/eval/expr.rs +++ b/src/eval/expr.rs @@ -174,9 +174,18 @@ impl Engine { // Check the variable resolver, if any if let Some(ref resolve_var) = self.resolve_var { + let orig_scope_len = scope.len(); + let context = EvalContext::new(self, global, caches, scope, this_ptr); let var_name = expr.get_variable_name(true).expect("`Expr::Variable`"); - match resolve_var(var_name, index, context) { + let resolved_var = resolve_var(var_name, index, context); + + if orig_scope_len != scope.len() { + // The scope is changed, always search from now on + global.always_search_scope = true; + } + + match resolved_var { Ok(Some(mut result)) => { result.set_access_mode(AccessMode::ReadOnly); return Ok(result.into()); diff --git a/src/eval/stmt.rs b/src/eval/stmt.rs index db2523ff..f9111ce6 100644 --- a/src/eval/stmt.rs +++ b/src/eval/stmt.rs @@ -728,10 +728,17 @@ impl Engine { nesting_level: global.scope_level, will_shadow, }; + let orig_scope_len = scope.len(); let context = EvalContext::new(self, global, caches, scope, this_ptr.as_deref_mut()); + let filter_result = filter(true, info, context); - if !filter(true, info, context)? { + if orig_scope_len != scope.len() { + // The scope is changed, always search from now on + global.always_search_scope = true; + } + + if !filter_result? { return Err(ERR::ErrorForbiddenVariable(var_name.to_string(), *pos).into()); } }