Fix positions.
This commit is contained in:
@@ -147,7 +147,6 @@ impl Engine {
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
ChainType::Indexing => {
|
||||
let pos = rhs.start_position();
|
||||
let root_pos = idx_val.position();
|
||||
let idx_val = idx_val.into_index_value().expect("`ChainType::Index`");
|
||||
|
||||
match rhs {
|
||||
@@ -190,7 +189,7 @@ impl Engine {
|
||||
)
|
||||
.or_else(|idx_err| match *idx_err {
|
||||
ERR::ErrorIndexingType(..) => Ok((Dynamic::UNIT, false)),
|
||||
_ => Err(idx_err.fill_position(root_pos)),
|
||||
_ => Err(idx_err),
|
||||
})?;
|
||||
}
|
||||
|
||||
@@ -231,8 +230,7 @@ impl Engine {
|
||||
let new_val = &mut new_val;
|
||||
self.call_indexer_set(
|
||||
global, state, lib, target, idx, new_val, is_ref_mut, level,
|
||||
)
|
||||
.map_err(|err| err.fill_position(root_pos))?;
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok((Dynamic::UNIT, true))
|
||||
@@ -506,7 +504,7 @@ impl Engine {
|
||||
.map_err(
|
||||
|idx_err| match *idx_err {
|
||||
ERR::ErrorIndexingType(..) => err,
|
||||
_ => idx_err.fill_position(pos),
|
||||
_ => idx_err,
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -553,12 +551,12 @@ impl Engine {
|
||||
is_ref_mut, level,
|
||||
)
|
||||
.or_else(|idx_err| match *idx_err {
|
||||
// If there is no setter, no need to feed it
|
||||
// back because the property is read-only
|
||||
ERR::ErrorIndexingType(..) => {
|
||||
// If there is no setter, no need to feed it back because
|
||||
// the property is read-only
|
||||
Ok((Dynamic::UNIT, false))
|
||||
}
|
||||
_ => Err(idx_err.fill_position(pos)),
|
||||
_ => Err(idx_err),
|
||||
})
|
||||
}
|
||||
_ => Err(err),
|
||||
@@ -872,7 +870,7 @@ impl Engine {
|
||||
lib: &[&Module],
|
||||
target: &'t mut Dynamic,
|
||||
idx: Dynamic,
|
||||
pos: Position,
|
||||
idx_pos: Position,
|
||||
add_if_not_found: bool,
|
||||
use_indexers: bool,
|
||||
level: usize,
|
||||
@@ -889,10 +887,10 @@ impl Engine {
|
||||
// val_array[idx]
|
||||
let index = idx
|
||||
.as_int()
|
||||
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, pos))?;
|
||||
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, idx_pos))?;
|
||||
let len = arr.len();
|
||||
let arr_idx = super::calc_index(len, index, true, || {
|
||||
ERR::ErrorArrayBounds(len, index, pos).into()
|
||||
ERR::ErrorArrayBounds(len, index, idx_pos).into()
|
||||
})?;
|
||||
|
||||
Ok(arr.get_mut(arr_idx).map(Target::from).unwrap())
|
||||
@@ -903,10 +901,10 @@ impl Engine {
|
||||
// val_blob[idx]
|
||||
let index = idx
|
||||
.as_int()
|
||||
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, pos))?;
|
||||
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, idx_pos))?;
|
||||
let len = arr.len();
|
||||
let arr_idx = super::calc_index(len, index, true, || {
|
||||
ERR::ErrorArrayBounds(len, index, pos).into()
|
||||
ERR::ErrorArrayBounds(len, index, idx_pos).into()
|
||||
})?;
|
||||
|
||||
let value = arr.get(arr_idx).map(|&v| (v as crate::INT).into()).unwrap();
|
||||
@@ -922,7 +920,7 @@ impl Engine {
|
||||
Dynamic(Union::Map(map, ..)) => {
|
||||
// val_map[idx]
|
||||
let index = idx.read_lock::<crate::ImmutableString>().ok_or_else(|| {
|
||||
self.make_type_mismatch_err::<crate::ImmutableString>(idx.type_name(), pos)
|
||||
self.make_type_mismatch_err::<crate::ImmutableString>(idx.type_name(), idx_pos)
|
||||
})?;
|
||||
|
||||
if _add_if_not_found && !map.contains_key(index.as_str()) {
|
||||
@@ -932,7 +930,7 @@ impl Engine {
|
||||
if let Some(value) = map.get_mut(index.as_str()) {
|
||||
Ok(Target::from(value))
|
||||
} else if self.fail_on_invalid_map_property() {
|
||||
Err(ERR::ErrorPropertyNotFound(index.to_string(), pos).into())
|
||||
Err(ERR::ErrorPropertyNotFound(index.to_string(), idx_pos).into())
|
||||
} else {
|
||||
Ok(Target::from(Dynamic::UNIT))
|
||||
}
|
||||
@@ -950,10 +948,10 @@ impl Engine {
|
||||
let end = range.end;
|
||||
|
||||
let start = super::calc_index(BITS, start, false, || {
|
||||
ERR::ErrorBitFieldBounds(BITS, start, pos).into()
|
||||
ERR::ErrorBitFieldBounds(BITS, start, idx_pos).into()
|
||||
})?;
|
||||
let end = super::calc_index(BITS, end, false, || {
|
||||
ERR::ErrorBitFieldBounds(BITS, end, pos).into()
|
||||
ERR::ErrorBitFieldBounds(BITS, end, idx_pos).into()
|
||||
})?;
|
||||
|
||||
if end <= start {
|
||||
@@ -975,10 +973,10 @@ impl Engine {
|
||||
let end = *range.end();
|
||||
|
||||
let start = super::calc_index(BITS, start, false, || {
|
||||
ERR::ErrorBitFieldBounds(BITS, start, pos).into()
|
||||
ERR::ErrorBitFieldBounds(BITS, start, idx_pos).into()
|
||||
})?;
|
||||
let end = super::calc_index(BITS, end, false, || {
|
||||
ERR::ErrorBitFieldBounds(BITS, end, pos).into()
|
||||
ERR::ErrorBitFieldBounds(BITS, end, idx_pos).into()
|
||||
})?;
|
||||
|
||||
if end < start {
|
||||
@@ -1014,12 +1012,12 @@ impl Engine {
|
||||
// val_int[idx]
|
||||
let index = idx
|
||||
.as_int()
|
||||
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, pos))?;
|
||||
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, idx_pos))?;
|
||||
|
||||
const BITS: usize = std::mem::size_of::<crate::INT>() * 8;
|
||||
|
||||
let bit = super::calc_index(BITS, index, true, || {
|
||||
ERR::ErrorBitFieldBounds(BITS, index, pos).into()
|
||||
ERR::ErrorBitFieldBounds(BITS, index, idx_pos).into()
|
||||
})?;
|
||||
|
||||
let bit_value = (*value & (1 << bit)) != 0;
|
||||
@@ -1036,14 +1034,14 @@ impl Engine {
|
||||
// val_string[idx]
|
||||
let index = idx
|
||||
.as_int()
|
||||
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, pos))?;
|
||||
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, idx_pos))?;
|
||||
|
||||
let (ch, offset) = if index >= 0 {
|
||||
let offset = index as usize;
|
||||
(
|
||||
s.chars().nth(offset).ok_or_else(|| {
|
||||
let chars_len = s.chars().count();
|
||||
ERR::ErrorStringBounds(chars_len, index, pos)
|
||||
ERR::ErrorStringBounds(chars_len, index, idx_pos)
|
||||
})?,
|
||||
offset,
|
||||
)
|
||||
@@ -1053,13 +1051,13 @@ impl Engine {
|
||||
// Count from end if negative
|
||||
s.chars().rev().nth(offset - 1).ok_or_else(|| {
|
||||
let chars_len = s.chars().count();
|
||||
ERR::ErrorStringBounds(chars_len, index, pos)
|
||||
ERR::ErrorStringBounds(chars_len, index, idx_pos)
|
||||
})?,
|
||||
offset,
|
||||
)
|
||||
} else {
|
||||
let chars_len = s.chars().count();
|
||||
return Err(ERR::ErrorStringBounds(chars_len, index, pos).into());
|
||||
return Err(ERR::ErrorStringBounds(chars_len, index, idx_pos).into());
|
||||
};
|
||||
|
||||
Ok(Target::StringChar {
|
||||
|
@@ -327,8 +327,7 @@ impl Engine {
|
||||
Expr::Unit(..) => Ok(Dynamic::UNIT),
|
||||
|
||||
// `... ${...} ...`
|
||||
Expr::InterpolatedString(x, pos) => {
|
||||
let mut pos = *pos;
|
||||
Expr::InterpolatedString(x, _) => {
|
||||
let mut concat: Dynamic = self.const_empty_string().into();
|
||||
let mut result = Ok(Dynamic::UNIT);
|
||||
|
||||
@@ -347,7 +346,7 @@ impl Engine {
|
||||
state,
|
||||
lib,
|
||||
Some(OpAssignment::new(OP_CONCAT)),
|
||||
pos,
|
||||
expr.start_position(),
|
||||
&mut (&mut concat).into(),
|
||||
("", Position::NONE),
|
||||
item,
|
||||
@@ -356,8 +355,6 @@ impl Engine {
|
||||
result = Err(err.fill_position(expr.start_position()));
|
||||
break;
|
||||
}
|
||||
|
||||
pos = expr.start_position();
|
||||
}
|
||||
|
||||
result.map(|_| concat)
|
||||
|
Reference in New Issue
Block a user