mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 22:47:43 +02:00
* error for division by zero with = * cargo fmt * add helper zero_division_error * tests for zero division error * fix test names (zero div error)
This commit is contained in:
@ -47,7 +47,10 @@ pub(crate) async fn evaluate_baseline_expr(
|
||||
match binary.op.expr {
|
||||
Expression::Literal(hir::Literal::Operator(op)) => {
|
||||
match apply_operator(op, &left, &right) {
|
||||
Ok(result) => Ok(result.into_value(tag)),
|
||||
Ok(result) => match result {
|
||||
UntaggedValue::Error(shell_err) => Err(shell_err),
|
||||
_ => Ok(result.into_value(tag)),
|
||||
},
|
||||
Err((left_type, right_type)) => Err(ShellError::coerce_error(
|
||||
left_type.spanned(binary.left.span),
|
||||
right_type.spanned(binary.right.span),
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::data::value;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::hir::Operator;
|
||||
use nu_protocol::{Primitive, ShellTypeName, UntaggedValue, Value};
|
||||
use std::ops::Not;
|
||||
@ -24,7 +25,14 @@ pub fn apply_operator(
|
||||
Operator::Plus => value::compute_values(op, left, right),
|
||||
Operator::Minus => value::compute_values(op, left, right),
|
||||
Operator::Multiply => value::compute_values(op, left, right),
|
||||
Operator::Divide => value::compute_values(op, left, right),
|
||||
Operator::Divide => value::compute_values(op, left, right).map(|res| match res {
|
||||
UntaggedValue::Error(_) => UntaggedValue::Error(ShellError::labeled_error(
|
||||
"Evaluation error",
|
||||
"division by zero",
|
||||
&right.tag.span,
|
||||
)),
|
||||
_ => res,
|
||||
}),
|
||||
Operator::In => table_contains(left, right).map(UntaggedValue::boolean),
|
||||
Operator::NotIn => table_contains(left, right).map(|x| UntaggedValue::boolean(!x)),
|
||||
Operator::And => match (left.as_bool(), right.as_bool()) {
|
||||
|
Reference in New Issue
Block a user