Fix for loop operations.
This commit is contained in:
parent
3c7cd8e278
commit
3d06ddc6e2
@ -686,51 +686,53 @@ impl Engine {
|
|||||||
|
|
||||||
let mut result = Dynamic::UNIT;
|
let mut result = Dynamic::UNIT;
|
||||||
|
|
||||||
for (x, iter_value) in iter_func(iter_obj).enumerate() {
|
if body.is_empty() {
|
||||||
// Increment counter
|
for _ in iter_func(iter_obj) {
|
||||||
if let Some(counter_index) = counter_index {
|
self.track_operation(global, body.position())?;
|
||||||
// As the variable increments from 0, this should always work
|
}
|
||||||
// since any overflow will first be caught below.
|
} else {
|
||||||
let index_value = x as INT;
|
for (x, iter_value) in iter_func(iter_obj).enumerate() {
|
||||||
|
// Increment counter
|
||||||
|
if let Some(counter_index) = counter_index {
|
||||||
|
// As the variable increments from 0, this should always work
|
||||||
|
// since any overflow will first be caught below.
|
||||||
|
let index_value = x as INT;
|
||||||
|
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[allow(clippy::absurd_extreme_comparisons)]
|
#[allow(clippy::absurd_extreme_comparisons)]
|
||||||
if index_value > crate::MAX_USIZE_INT {
|
if index_value > crate::MAX_USIZE_INT {
|
||||||
return Err(ERR::ErrorArithmetic(
|
return Err(ERR::ErrorArithmetic(
|
||||||
format!("for-loop counter overflow: {x}"),
|
format!("for-loop counter overflow: {x}"),
|
||||||
counter.pos,
|
counter.pos,
|
||||||
)
|
)
|
||||||
.into());
|
.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
*scope.get_mut_by_index(counter_index).write_lock().unwrap() =
|
||||||
|
Dynamic::from_int(index_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
*scope.get_mut_by_index(counter_index).write_lock().unwrap() =
|
// Set loop value
|
||||||
Dynamic::from_int(index_value);
|
let value = iter_value
|
||||||
}
|
.map_err(|err| err.fill_position(expr.position()))?
|
||||||
|
.flatten();
|
||||||
|
|
||||||
// Set loop value
|
*scope.get_mut_by_index(index).write_lock().unwrap() = value;
|
||||||
let value = iter_value
|
|
||||||
.map_err(|err| err.fill_position(expr.position()))?
|
|
||||||
.flatten();
|
|
||||||
|
|
||||||
*scope.get_mut_by_index(index).write_lock().unwrap() = value;
|
// Run block
|
||||||
|
let this_ptr = this_ptr.as_deref_mut();
|
||||||
|
|
||||||
// Run block
|
match self.eval_stmt_block(global, caches, scope, this_ptr, body, true) {
|
||||||
if body.is_empty() {
|
Ok(_) => (),
|
||||||
continue;
|
Err(err) => match *err {
|
||||||
}
|
ERR::LoopBreak(false, ..) => (),
|
||||||
|
ERR::LoopBreak(true, value, ..) => {
|
||||||
let this_ptr = this_ptr.as_deref_mut();
|
result = value;
|
||||||
|
break;
|
||||||
match self.eval_stmt_block(global, caches, scope, this_ptr, body, true) {
|
}
|
||||||
Ok(_) => (),
|
_ => return Err(err),
|
||||||
Err(err) => match *err {
|
},
|
||||||
ERR::LoopBreak(false, ..) => (),
|
}
|
||||||
ERR::LoopBreak(true, value, ..) => {
|
|
||||||
result = value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_ => return Err(err),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user