Fix test.
This commit is contained in:
parent
9c4ed44ab8
commit
f49ff28b82
@ -1,13 +1,12 @@
|
||||
//! Module implementing the [`AST`] optimizer.
|
||||
#![cfg(not(feature = "no_optimize"))]
|
||||
|
||||
use crate::ast::{Expr, OpAssignment, ScriptFnDef, Stmt, StmtBlock, AST_OPTION_FLAGS::*};
|
||||
use crate::ast::{Expr, OpAssignment, ScriptFnDef, Stmt, AST_OPTION_FLAGS::*};
|
||||
use crate::engine::{
|
||||
EvalState, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_PRINT, KEYWORD_TYPE_OF,
|
||||
};
|
||||
use crate::func::builtin::get_builtin_binary_op_fn;
|
||||
use crate::func::hashing::get_hasher;
|
||||
use crate::func::native::shared_take_or_clone;
|
||||
use crate::tokenizer::Token;
|
||||
use crate::types::dynamic::AccessMode;
|
||||
use crate::{
|
||||
@ -1149,7 +1148,7 @@ pub fn optimize_into_ast(
|
||||
.map(|fn_def| ScriptFnDef {
|
||||
name: fn_def.name.clone(),
|
||||
access: fn_def.access,
|
||||
body: StmtBlock::NONE,
|
||||
body: crate::ast::StmtBlock::NONE,
|
||||
params: fn_def.params.clone(),
|
||||
lib: None,
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
@ -1167,7 +1166,7 @@ pub fn optimize_into_ast(
|
||||
_functions
|
||||
.into_iter()
|
||||
.map(|fn_def| {
|
||||
let mut fn_def = shared_take_or_clone(fn_def);
|
||||
let mut fn_def = crate::func::native::shared_take_or_clone(fn_def);
|
||||
|
||||
// Optimize the function body
|
||||
let body = mem::take(fn_def.body.deref_mut());
|
||||
|
@ -223,10 +223,12 @@ struct ParseSettings {
|
||||
/// Is the construct being parsed located at global level?
|
||||
is_global: bool,
|
||||
/// Is the construct being parsed located at function definition level?
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
is_function_scope: bool,
|
||||
/// Is the current position inside a loop?
|
||||
is_breakable: bool,
|
||||
/// Is anonymous function allowed?
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
allow_anonymous_fn: bool,
|
||||
/// Is if-expression allowed?
|
||||
allow_if_expr: bool,
|
||||
@ -1315,6 +1317,7 @@ fn parse_primary(
|
||||
(None, None, state.get_identifier(s)).into(),
|
||||
),
|
||||
// Access to `this` as a variable is OK within a function scope
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
_ if &*s == KEYWORD_THIS && settings.is_function_scope => Expr::Variable(
|
||||
None,
|
||||
settings.pos,
|
||||
@ -3232,8 +3235,10 @@ impl Engine {
|
||||
allow_if_expr: false,
|
||||
allow_switch_expr: false,
|
||||
allow_stmt_expr: false,
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
allow_anonymous_fn: false,
|
||||
is_global: true,
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
is_function_scope: false,
|
||||
is_breakable: false,
|
||||
level: 0,
|
||||
@ -3281,8 +3286,10 @@ impl Engine {
|
||||
allow_if_expr: true,
|
||||
allow_switch_expr: true,
|
||||
allow_stmt_expr: true,
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
allow_anonymous_fn: true,
|
||||
is_global: true,
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
is_function_scope: false,
|
||||
is_breakable: false,
|
||||
level: 0,
|
||||
|
@ -129,7 +129,7 @@ fn test_fn_ptr_call() -> Result<(), Box<EvalAltResult>> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
fn test_fn_ptr_make_closure() -> Result<(), Box<EvalAltResult>> {
|
||||
let f = {
|
||||
let engine = Engine::new();
|
||||
|
Loading…
Reference in New Issue
Block a user