Prevent spill-over of new variables in Engine::call_fn.

This commit is contained in:
Stephen Chung 2021-08-17 23:24:41 +08:00
parent b6eac65601
commit 58352e00bd
2 changed files with 4 additions and 0 deletions

View File

@ -8,6 +8,7 @@ Bug fixes
--------- ---------
* Custom syntax starting with a disabled standard keyword now works properly. * Custom syntax starting with a disabled standard keyword now works properly.
* When calling `Engine::call_fn`, new variables defined during evaluation of the body script are removed and no longer spill into the function call.
Enhancements Enhancements
------------ ------------

View File

@ -1979,7 +1979,10 @@ impl Engine {
let statements = ast.statements(); let statements = ast.statements();
if eval_ast && !statements.is_empty() { if eval_ast && !statements.is_empty() {
// Make sure new variables introduced at global level do not _spill_ into the function call
let orig_scope_len = scope.len();
self.eval_global_statements(scope, mods, state, statements, lib, 0)?; self.eval_global_statements(scope, mods, state, statements, lib, 0)?;
scope.rewind(orig_scope_len);
} }
let fn_def = ast let fn_def = ast