Fix tests.

This commit is contained in:
Stephen Chung 2021-06-02 15:05:33 +08:00
parent 71684f5e2a
commit 4cf6550fc6
4 changed files with 20 additions and 18 deletions

View File

@ -441,7 +441,6 @@ impl<'a> Target<'a> {
} }
/// Propagate a changed value back to the original source. /// Propagate a changed value back to the original source.
/// This has no effect except for string indexing. /// This has no effect except for string indexing.
#[cfg(not(feature = "no_object"))]
#[inline(always)] #[inline(always)]
pub fn propagate_changed_value(&mut self) -> Result<(), Box<EvalAltResult>> { pub fn propagate_changed_value(&mut self) -> Result<(), Box<EvalAltResult>> {
match self { match self {

View File

@ -670,7 +670,7 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut State, preserve_result: bool) {
} }
/// Optimize an [expression][Expr]. /// Optimize an [expression][Expr].
fn optimize_expr(expr: &mut Expr, state: &mut State, indexing: bool) { fn optimize_expr(expr: &mut Expr, state: &mut State, _chaining: bool) {
// These keywords are handled specially // These keywords are handled specially
const DONT_EVAL_KEYWORDS: &[&str] = &[ const DONT_EVAL_KEYWORDS: &[&str] = &[
KEYWORD_PRINT, // side effects KEYWORD_PRINT, // side effects
@ -693,7 +693,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut State, indexing: bool) {
} }
// lhs.rhs // lhs.rhs
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
Expr::Dot(x, _) if !indexing => match (&mut x.lhs, &mut x.rhs) { Expr::Dot(x, _) if !_chaining => match (&mut x.lhs, &mut x.rhs) {
// map.string // map.string
(Expr::Map(m, pos), Expr::Property(p)) if m.0.iter().all(|(_, x)| x.is_pure()) => { (Expr::Map(m, pos), Expr::Property(p)) if m.0.iter().all(|(_, x)| x.is_pure()) => {
let prop = p.2.0.as_str(); let prop = p.2.0.as_str();
@ -711,11 +711,11 @@ fn optimize_expr(expr: &mut Expr, state: &mut State, indexing: bool) {
} }
// ....lhs.rhs // ....lhs.rhs
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
Expr::Dot(x, _) => { optimize_expr(&mut x.lhs, state, false); optimize_expr(&mut x.rhs, state, indexing); } Expr::Dot(x, _) => { optimize_expr(&mut x.lhs, state, false); optimize_expr(&mut x.rhs, state, _chaining); }
// lhs[rhs] // lhs[rhs]
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
Expr::Index(x, _) if !indexing => match (&mut x.lhs, &mut x.rhs) { Expr::Index(x, _) if !_chaining => match (&mut x.lhs, &mut x.rhs) {
// array[int] // array[int]
(Expr::Array(a, pos), Expr::IntegerConstant(i, _)) (Expr::Array(a, pos), Expr::IntegerConstant(i, _))
if *i >= 0 && (*i as usize) < a.len() && a.iter().all(Expr::is_pure) => if *i >= 0 && (*i as usize) < a.len() && a.iter().all(Expr::is_pure) =>
@ -778,7 +778,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut State, indexing: bool) {
}, },
// ...[lhs][rhs] // ...[lhs][rhs]
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
Expr::Index(x, _) => { optimize_expr(&mut x.lhs, state, false); optimize_expr(&mut x.rhs, state, indexing); } Expr::Index(x, _) => { optimize_expr(&mut x.lhs, state, false); optimize_expr(&mut x.rhs, state, _chaining); }
// `` // ``
Expr::InterpolatedString(x) if x.is_empty() => { Expr::InterpolatedString(x) if x.is_empty() => {
state.set_dirty(); state.set_dirty();

View File

@ -1,5 +1,5 @@
use crate::dynamic::Variant; use crate::dynamic::Variant;
use crate::{def_package, EvalAltResult, Position, INT}; use crate::{def_package, EvalAltResult, INT};
use std::ops::Range; use std::ops::Range;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
@ -29,9 +29,9 @@ where
Default::default(), Default::default(),
Box::new(EvalAltResult::ErrorArithmetic( Box::new(EvalAltResult::ErrorArithmetic(
"step value cannot be zero".to_string(), "step value cannot be zero".to_string(),
Position::NONE, crate::Position::NONE,
)), )),
Position::NONE, crate::Position::NONE,
) )
.into(); .into();
} }
@ -139,18 +139,21 @@ impl BitRange {
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
if offset >= BITS { if offset >= BITS {
return EvalAltResult::ErrorBitFieldBounds(BITS, from, Position::NONE).into(); return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
.into();
} }
offset offset
} else { } else {
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
if let Some(abs_from) = from.checked_abs() { if let Some(abs_from) = from.checked_abs() {
if (abs_from as usize) > BITS { if (abs_from as usize) > BITS {
return EvalAltResult::ErrorBitFieldBounds(BITS, from, Position::NONE).into(); return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
.into();
} }
BITS - (abs_from as usize) BITS - (abs_from as usize)
} else { } else {
return EvalAltResult::ErrorBitFieldBounds(BITS, from, Position::NONE).into(); return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
.into();
} }
#[cfg(feature = "unchecked")] #[cfg(feature = "unchecked")]
@ -255,8 +258,8 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
if step == 0.0 { if step == 0.0 {
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(), return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), Position::NONE)), Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)),
Position::NONE, crate::Position::NONE,
).into(); ).into();
} }
@ -317,8 +320,8 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
if step.is_zero() { if step.is_zero() {
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(), return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), Position::NONE)), Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)),
Position::NONE, crate::Position::NONE,
).into(); ).into();
} }

View File

@ -15,7 +15,7 @@ use crate::token::{
}; };
use crate::utils::{get_hasher, IdentifierBuilder}; use crate::utils::{get_hasher, IdentifierBuilder};
use crate::{ use crate::{
calc_fn_hash, calc_qualified_fn_hash, Dynamic, Engine, FnPtr, Identifier, LexError, ParseError, calc_fn_hash, calc_qualified_fn_hash, Dynamic, Engine, Identifier, LexError, ParseError,
ParseErrorType, Position, Scope, Shared, StaticVec, AST, ParseErrorType, Position, Scope, Shared, StaticVec, AST,
}; };
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
@ -3017,7 +3017,7 @@ fn parse_anon_fn(
comments: Default::default(), comments: Default::default(),
}; };
let fn_ptr = FnPtr::new_unchecked(fn_name.into(), Default::default()); let fn_ptr = crate::FnPtr::new_unchecked(fn_name.into(), Default::default());
let expr = Expr::DynamicConstant(Box::new(fn_ptr.into()), settings.pos); let expr = Expr::DynamicConstant(Box::new(fn_ptr.into()), settings.pos);
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]