From dd36f3387a57810950fb33f6bea16122dfd95129 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 14 Mar 2020 20:06:40 +0800 Subject: [PATCH] Fixup code to make sure all feature builds succeed. --- src/builtin.rs | 4 +++- src/call.rs | 2 ++ src/lib.rs | 5 ++++- src/optimize.rs | 2 ++ src/scope.rs | 23 ++++++++++++++--------- tests/constants.rs | 1 + tests/power_of.rs | 5 ++++- 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/builtin.rs b/src/builtin.rs index da139f60..b69429f4 100644 --- a/src/builtin.rs +++ b/src/builtin.rs @@ -8,7 +8,9 @@ use crate::engine::Engine; use crate::fn_register::{RegisterFn, RegisterResultFn}; use crate::parser::{Position, INT}; use crate::result::EvalAltResult; -use crate::FLOAT; + +#[cfg(not(feature = "no_float"))] +use crate::parser::FLOAT; use num_traits::{ identities::Zero, CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl, diff --git a/src/call.rs b/src/call.rs index 9a2252c0..2a2822eb 100644 --- a/src/call.rs +++ b/src/call.rs @@ -1,6 +1,8 @@ //! Helper module which defines `FnArgs` to make function calling easier. use crate::any::{Any, Dynamic}; + +#[cfg(not(feature = "no_index"))] use crate::engine::Array; /// Trait that represent arguments to a function call. diff --git a/src/lib.rs b/src/lib.rs index 93d1699f..47be664d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,9 +78,12 @@ pub use call::FuncArgs; pub use engine::Engine; pub use error::{ParseError, ParseErrorType}; pub use fn_register::{RegisterDynamicFn, RegisterFn, RegisterResultFn}; -pub use parser::{Position, AST, FLOAT, INT}; +pub use parser::{Position, AST, INT}; pub use result::EvalAltResult; pub use scope::{Scope, ScopeEntry, VariableType}; #[cfg(not(feature = "no_index"))] pub use engine::Array; + +#[cfg(not(feature = "no_float"))] +pub use parser::FLOAT; diff --git a/src/optimize.rs b/src/optimize.rs index 2e2e7778..f2352afa 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -1,3 +1,5 @@ +#![cfg(not(feature = "no_optimize"))] + use crate::engine::KEYWORD_DUMP_AST; use crate::parser::{Expr, Stmt}; use crate::scope::{Scope, ScopeEntry, VariableType}; diff --git a/src/scope.rs b/src/scope.rs index 291af905..081237fd 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -221,15 +221,6 @@ fn map_dynamic_to_expr(value: Dynamic) -> (Option, Dynamic) { )), value2, ) - } else if value.is::() { - let value2 = value.clone(); - ( - Some(Expr::FloatConstant( - *value.downcast::().expect("value should be FLOAT"), - Position::none(), - )), - value2, - ) } else if value.is::() { let value2 = value.clone(); ( @@ -261,6 +252,20 @@ fn map_dynamic_to_expr(value: Dynamic) -> (Option, Dynamic) { value2, ) } else { + #[cfg(not(feature = "no_float"))] + { + if value.is::() { + let value2 = value.clone(); + return ( + Some(Expr::FloatConstant( + *value.downcast::().expect("value should be FLOAT"), + Position::none(), + )), + value2, + ); + } + } + (None, value) } } diff --git a/tests/constants.rs b/tests/constants.rs index ff668797..f931e76b 100644 --- a/tests/constants.rs +++ b/tests/constants.rs @@ -12,6 +12,7 @@ fn test_constant() -> Result<(), EvalAltResult> { Ok(_) => panic!("expecting compilation error"), } + #[cfg(not(feature = "no_index"))] match engine.eval::("const x = [1, 2, 3, 4, 5]; x[2] = 42;") { Err(EvalAltResult::ErrorAssignmentToConstant(var, _)) if var == "x" => (), Err(err) => return Err(err), diff --git a/tests/power_of.rs b/tests/power_of.rs index 8e1ed522..f02a2e52 100644 --- a/tests/power_of.rs +++ b/tests/power_of.rs @@ -1,4 +1,7 @@ -use rhai::{Engine, EvalAltResult, FLOAT, INT}; +use rhai::{Engine, EvalAltResult, INT}; + +#[cfg(not(feature = "no_float"))] +use rhai::FLOAT; #[test] fn test_power_of() -> Result<(), EvalAltResult> {