diff --git a/CHANGELOG.md b/CHANGELOG.md index 93f20647..c12e8938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Bug fixes --------- * 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 ------------ diff --git a/src/engine_api.rs b/src/engine_api.rs index fd487c82..181e59d8 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -1979,7 +1979,10 @@ impl Engine { let statements = ast.statements(); 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)?; + scope.rewind(orig_scope_len); } let fn_def = ast