Fix tests.
This commit is contained in:
parent
71684f5e2a
commit
4cf6550fc6
@ -441,7 +441,6 @@ impl<'a> Target<'a> {
|
||||
}
|
||||
/// Propagate a changed value back to the original source.
|
||||
/// This has no effect except for string indexing.
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
#[inline(always)]
|
||||
pub fn propagate_changed_value(&mut self) -> Result<(), Box<EvalAltResult>> {
|
||||
match self {
|
||||
|
@ -670,7 +670,7 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut State, preserve_result: bool) {
|
||||
}
|
||||
|
||||
/// 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
|
||||
const DONT_EVAL_KEYWORDS: &[&str] = &[
|
||||
KEYWORD_PRINT, // side effects
|
||||
@ -693,7 +693,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut State, indexing: bool) {
|
||||
}
|
||||
// lhs.rhs
|
||||
#[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
|
||||
(Expr::Map(m, pos), Expr::Property(p)) if m.0.iter().all(|(_, x)| x.is_pure()) => {
|
||||
let prop = p.2.0.as_str();
|
||||
@ -711,11 +711,11 @@ fn optimize_expr(expr: &mut Expr, state: &mut State, indexing: bool) {
|
||||
}
|
||||
// ....lhs.rhs
|
||||
#[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]
|
||||
#[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]
|
||||
(Expr::Array(a, pos), Expr::IntegerConstant(i, _))
|
||||
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]
|
||||
#[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() => {
|
||||
state.set_dirty();
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::dynamic::Variant;
|
||||
use crate::{def_package, EvalAltResult, Position, INT};
|
||||
use crate::{def_package, EvalAltResult, INT};
|
||||
use std::ops::Range;
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@ -29,9 +29,9 @@ where
|
||||
Default::default(),
|
||||
Box::new(EvalAltResult::ErrorArithmetic(
|
||||
"step value cannot be zero".to_string(),
|
||||
Position::NONE,
|
||||
crate::Position::NONE,
|
||||
)),
|
||||
Position::NONE,
|
||||
crate::Position::NONE,
|
||||
)
|
||||
.into();
|
||||
}
|
||||
@ -139,18 +139,21 @@ impl BitRange {
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if offset >= BITS {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, from, Position::NONE).into();
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
|
||||
.into();
|
||||
}
|
||||
offset
|
||||
} else {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if let Some(abs_from) = from.checked_abs() {
|
||||
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)
|
||||
} else {
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, from, Position::NONE).into();
|
||||
return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE)
|
||||
.into();
|
||||
}
|
||||
|
||||
#[cfg(feature = "unchecked")]
|
||||
@ -255,8 +258,8 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if step == 0.0 {
|
||||
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
|
||||
Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), Position::NONE)),
|
||||
Position::NONE,
|
||||
Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)),
|
||||
crate::Position::NONE,
|
||||
).into();
|
||||
}
|
||||
|
||||
@ -317,8 +320,8 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
if step.is_zero() {
|
||||
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
|
||||
Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), Position::NONE)),
|
||||
Position::NONE,
|
||||
Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)),
|
||||
crate::Position::NONE,
|
||||
).into();
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ use crate::token::{
|
||||
};
|
||||
use crate::utils::{get_hasher, IdentifierBuilder};
|
||||
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,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
@ -3017,7 +3017,7 @@ fn parse_anon_fn(
|
||||
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);
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
|
Loading…
Reference in New Issue
Block a user