Fix builds.
This commit is contained in:
parent
68c0ee08c0
commit
71ad158b6a
@ -2059,7 +2059,7 @@ impl Engine {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
#[cfg(feature = "no_function")]
|
#[cfg(feature = "no_function")]
|
||||||
let lib = StaticVec::new();
|
let lib = crate::StaticVec::new();
|
||||||
|
|
||||||
let stmt = std::mem::take(ast.statements_mut());
|
let stmt = std::mem::take(ast.statements_mut());
|
||||||
crate::optimize::optimize_into_ast(self, scope, stmt, lib, optimization_level)
|
crate::optimize::optimize_into_ast(self, scope, stmt, lib, optimization_level)
|
||||||
|
@ -68,50 +68,48 @@ fn test_functions_namespaces() -> Result<(), Box<EvalAltResult>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_functions_global_module() -> Result<(), Box<EvalAltResult>> {
|
fn test_functions_global_module() -> Result<(), Box<EvalAltResult>> {
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
assert_eq!(
|
||||||
{
|
engine.eval::<INT>(
|
||||||
assert_eq!(
|
"
|
||||||
engine.eval::<INT>(
|
const ANSWER = 42;
|
||||||
"
|
|
||||||
const ANSWER = 42;
|
|
||||||
fn foo() { global::ANSWER }
|
|
||||||
foo()
|
|
||||||
"
|
|
||||||
)?,
|
|
||||||
42
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(matches!(*engine.run("
|
|
||||||
fn foo() { global::ANSWER }
|
fn foo() { global::ANSWER }
|
||||||
|
foo()
|
||||||
|
"
|
||||||
|
)?,
|
||||||
|
42
|
||||||
|
);
|
||||||
|
|
||||||
{
|
assert!(matches!(*engine.run("
|
||||||
const ANSWER = 42;
|
fn foo() { global::ANSWER }
|
||||||
foo()
|
|
||||||
}
|
|
||||||
").expect_err("should error"),
|
|
||||||
EvalAltResult::ErrorInFunctionCall(_, _, err, _)
|
|
||||||
if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, _) if v == "global::ANSWER")
|
|
||||||
));
|
|
||||||
|
|
||||||
let mut module = Module::new();
|
{
|
||||||
module.set_var("ANSWER", 123 as INT);
|
const ANSWER = 42;
|
||||||
engine.register_static_module("global", module.into());
|
foo()
|
||||||
|
}
|
||||||
|
").expect_err("should error"),
|
||||||
|
EvalAltResult::ErrorInFunctionCall(_, _, err, _)
|
||||||
|
if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, _) if v == "global::ANSWER")
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(
|
let mut module = Module::new();
|
||||||
engine.eval::<INT>(
|
module.set_var("ANSWER", 123 as INT);
|
||||||
"
|
engine.register_static_module("global", module.into());
|
||||||
const ANSWER = 42;
|
|
||||||
fn foo() { global::ANSWER }
|
assert_eq!(
|
||||||
foo()
|
engine.eval::<INT>(
|
||||||
"
|
"
|
||||||
)?,
|
const ANSWER = 42;
|
||||||
123
|
fn foo() { global::ANSWER }
|
||||||
);
|
foo()
|
||||||
}
|
"
|
||||||
|
)?,
|
||||||
|
123
|
||||||
|
);
|
||||||
|
|
||||||
engine.register_result_fn(
|
engine.register_result_fn(
|
||||||
"do_stuff",
|
"do_stuff",
|
||||||
|
Loading…
Reference in New Issue
Block a user