From f49ff28b825623e5d65366c8feedda251889c50d Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 28 Nov 2021 10:49:48 +0800 Subject: [PATCH] Fix test. --- src/optimizer.rs | 7 +++---- src/parser.rs | 7 +++++++ tests/fn_ptr.rs | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/optimizer.rs b/src/optimizer.rs index 36629c6b..ce10d07b 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -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()); diff --git a/src/parser.rs b/src/parser.rs index ffdb63c5..6ce9314a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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, diff --git a/tests/fn_ptr.rs b/tests/fn_ptr.rs index 3dbc6e4c..bf513a08 100644 --- a/tests/fn_ptr.rs +++ b/tests/fn_ptr.rs @@ -129,7 +129,7 @@ fn test_fn_ptr_call() -> Result<(), Box> { } #[test] -#[cfg(not(feature = "no_function"))] +#[cfg(not(feature = "no_closure"))] fn test_fn_ptr_make_closure() -> Result<(), Box> { let f = { let engine = Engine::new();