From 31d045279ff4fdf0111b11eb15484294536c7f00 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 14 Oct 2022 11:57:36 +0800 Subject: [PATCH] Fix imports in eval. --- CHANGELOG.md | 11 ++++++----- src/func/call.rs | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c2848dd..2873c736 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ Rhai Release Notes Version 1.11.0 ============== +Bug fixes +--------- + +* `Engine::parse_json` now returns an error on unquoted keys to be consistent with JSON specifications. +* `import` statements inside `eval` no longer cause errors in subsequent code. + New features ------------ @@ -12,11 +18,6 @@ New features * It is now possible to specify a fixed _seed_ for use with the `ahash` hasher, via an environment variable, in order to force stable (i.e. deterministic) hashes for function signatures. This is necessary when using Rhai across shared-library boundaries. * A build script is now used to extract the environment variable (`RHAI_AHASH_SEED`) and splice it into the source code before compilation. -Bug fixes ---------- - -* `Engine::parse_json` now returns an error on unquoted keys to be consistent with JSON specifications. - Enhancements ------------ diff --git a/src/func/call.rs b/src/func/call.rs index c093c237..ce83786f 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -1137,6 +1137,7 @@ impl Engine { KEYWORD_EVAL if total_args == 1 => { // eval - only in function call style let orig_scope_len = scope.len(); + let orig_imports_len = global.num_imports(); let arg = first_arg.unwrap(); let (arg_value, pos) = self.get_arg_value(scope, global, caches, lib, this_ptr, arg, level)?; @@ -1155,7 +1156,8 @@ impl Engine { // IMPORTANT! If the eval defines new variables in the current scope, // all variable offsets from this point on will be mis-aligned. - if scope.len() != orig_scope_len { + // The same is true for imports. + if scope.len() != orig_scope_len || global.num_imports() != orig_imports_len { global.always_search_scope = true; }