Fixup code to make sure all feature builds succeed.

This commit is contained in:
Stephen Chung 2020-03-14 20:06:40 +08:00
parent 973153e832
commit dd36f3387a
7 changed files with 30 additions and 12 deletions

View File

@ -8,7 +8,9 @@ use crate::engine::Engine;
use crate::fn_register::{RegisterFn, RegisterResultFn}; use crate::fn_register::{RegisterFn, RegisterResultFn};
use crate::parser::{Position, INT}; use crate::parser::{Position, INT};
use crate::result::EvalAltResult; use crate::result::EvalAltResult;
use crate::FLOAT;
#[cfg(not(feature = "no_float"))]
use crate::parser::FLOAT;
use num_traits::{ use num_traits::{
identities::Zero, CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl, identities::Zero, CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl,

View File

@ -1,6 +1,8 @@
//! Helper module which defines `FnArgs` to make function calling easier. //! Helper module which defines `FnArgs` to make function calling easier.
use crate::any::{Any, Dynamic}; use crate::any::{Any, Dynamic};
#[cfg(not(feature = "no_index"))]
use crate::engine::Array; use crate::engine::Array;
/// Trait that represent arguments to a function call. /// Trait that represent arguments to a function call.

View File

@ -78,9 +78,12 @@ pub use call::FuncArgs;
pub use engine::Engine; pub use engine::Engine;
pub use error::{ParseError, ParseErrorType}; pub use error::{ParseError, ParseErrorType};
pub use fn_register::{RegisterDynamicFn, RegisterFn, RegisterResultFn}; 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 result::EvalAltResult;
pub use scope::{Scope, ScopeEntry, VariableType}; pub use scope::{Scope, ScopeEntry, VariableType};
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
pub use engine::Array; pub use engine::Array;
#[cfg(not(feature = "no_float"))]
pub use parser::FLOAT;

View File

@ -1,3 +1,5 @@
#![cfg(not(feature = "no_optimize"))]
use crate::engine::KEYWORD_DUMP_AST; use crate::engine::KEYWORD_DUMP_AST;
use crate::parser::{Expr, Stmt}; use crate::parser::{Expr, Stmt};
use crate::scope::{Scope, ScopeEntry, VariableType}; use crate::scope::{Scope, ScopeEntry, VariableType};

View File

@ -221,15 +221,6 @@ fn map_dynamic_to_expr(value: Dynamic) -> (Option<Expr>, Dynamic) {
)), )),
value2, value2,
) )
} else if value.is::<FLOAT>() {
let value2 = value.clone();
(
Some(Expr::FloatConstant(
*value.downcast::<FLOAT>().expect("value should be FLOAT"),
Position::none(),
)),
value2,
)
} else if value.is::<char>() { } else if value.is::<char>() {
let value2 = value.clone(); let value2 = value.clone();
( (
@ -261,6 +252,20 @@ fn map_dynamic_to_expr(value: Dynamic) -> (Option<Expr>, Dynamic) {
value2, value2,
) )
} else { } else {
#[cfg(not(feature = "no_float"))]
{
if value.is::<FLOAT>() {
let value2 = value.clone();
return (
Some(Expr::FloatConstant(
*value.downcast::<FLOAT>().expect("value should be FLOAT"),
Position::none(),
)),
value2,
);
}
}
(None, value) (None, value)
} }
} }

View File

@ -12,6 +12,7 @@ fn test_constant() -> Result<(), EvalAltResult> {
Ok(_) => panic!("expecting compilation error"), Ok(_) => panic!("expecting compilation error"),
} }
#[cfg(not(feature = "no_index"))]
match engine.eval::<i64>("const x = [1, 2, 3, 4, 5]; x[2] = 42;") { match engine.eval::<i64>("const x = [1, 2, 3, 4, 5]; x[2] = 42;") {
Err(EvalAltResult::ErrorAssignmentToConstant(var, _)) if var == "x" => (), Err(EvalAltResult::ErrorAssignmentToConstant(var, _)) if var == "x" => (),
Err(err) => return Err(err), Err(err) => return Err(err),

View File

@ -1,4 +1,7 @@
use rhai::{Engine, EvalAltResult, FLOAT, INT}; use rhai::{Engine, EvalAltResult, INT};
#[cfg(not(feature = "no_float"))]
use rhai::FLOAT;
#[test] #[test]
fn test_power_of() -> Result<(), EvalAltResult> { fn test_power_of() -> Result<(), EvalAltResult> {