Fix bug with using self-contained AST with call_fn.
This commit is contained in:
parent
2a57bd9d25
commit
b23d64bec0
@ -1,6 +1,15 @@
|
|||||||
Rhai Release Notes
|
Rhai Release Notes
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
Version 1.8.0
|
||||||
|
=============
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
* Self-contained `AST` now works properly with `Engine::call_fn`.
|
||||||
|
|
||||||
|
|
||||||
Version 1.7.0
|
Version 1.7.0
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
@ -244,6 +244,12 @@ impl Engine {
|
|||||||
|
|
||||||
let orig_scope_len = scope.len();
|
let orig_scope_len = scope.len();
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_module"))]
|
||||||
|
let orig_embedded_module_resolver = std::mem::replace(
|
||||||
|
&mut global.embedded_module_resolver,
|
||||||
|
ast.resolver().cloned(),
|
||||||
|
);
|
||||||
|
|
||||||
if eval_ast && !statements.is_empty() {
|
if eval_ast && !statements.is_empty() {
|
||||||
self.eval_global_statements(scope, global, caches, statements, &[ast.as_ref()], 0)?;
|
self.eval_global_statements(scope, global, caches, statements, &[ast.as_ref()], 0)?;
|
||||||
|
|
||||||
@ -278,6 +284,11 @@ impl Engine {
|
|||||||
0,
|
0,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_module"))]
|
||||||
|
{
|
||||||
|
global.embedded_module_resolver = orig_embedded_module_resolver;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "debugging")]
|
#[cfg(feature = "debugging")]
|
||||||
if self.debugger.is_some() {
|
if self.debugger.is_some() {
|
||||||
global.debugger.status = crate::eval::DebuggerStatus::Terminate;
|
global.debugger.status = crate::eval::DebuggerStatus::Terminate;
|
||||||
|
@ -263,11 +263,11 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
{
|
{
|
||||||
let script = r#"
|
let script = r#"
|
||||||
fn foo() {
|
fn foo(x) {
|
||||||
import "hello" as h;
|
import "hello" as h;
|
||||||
h::answer
|
h::answer * x
|
||||||
}
|
}
|
||||||
foo() + { import "hello" as h; h::answer }
|
foo(1) + { import "hello" as h; h::answer }
|
||||||
"#;
|
"#;
|
||||||
let mut scope = Scope::new();
|
let mut scope = Scope::new();
|
||||||
|
|
||||||
@ -278,6 +278,10 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
assert_eq!(engine.eval_ast::<INT>(&ast)?, 84);
|
assert_eq!(engine.eval_ast::<INT>(&ast)?, 84);
|
||||||
|
|
||||||
assert!(engine.eval::<INT>(script).is_err());
|
assert!(engine.eval::<INT>(script).is_err());
|
||||||
|
|
||||||
|
let result: INT = engine.call_fn(&mut Scope::new(), &ast, "foo", (2 as INT,))?;
|
||||||
|
|
||||||
|
assert_eq!(result, 84);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user