mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
Edit operator type errors
This commit is contained in:
parent
4d3283e235
commit
caaa2472ec
4 changed files with 746 additions and 979 deletions
|
@ -156,13 +156,13 @@ pub(crate) fn compile_expression(
|
|||
Ok(())
|
||||
}
|
||||
Expr::BinaryOp(lhs, op, rhs) => {
|
||||
if let Expr::Operator(ref operator) = op.expr {
|
||||
if let Expr::Operator(operator) = op.expr {
|
||||
drop_input(builder)?;
|
||||
compile_binary_op(
|
||||
working_set,
|
||||
builder,
|
||||
lhs,
|
||||
operator.clone().into_spanned(op.span),
|
||||
operator.into_spanned(op.span),
|
||||
rhs,
|
||||
expr.span,
|
||||
out_reg,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,7 @@ use std::fmt::Display;
|
|||
|
||||
use super::{Expr, Expression};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Comparison {
|
||||
Equal,
|
||||
NotEqual,
|
||||
|
@ -21,7 +21,7 @@ pub enum Comparison {
|
|||
EndsWith,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Math {
|
||||
Plus,
|
||||
Concat,
|
||||
|
@ -33,14 +33,14 @@ pub enum Math {
|
|||
Pow,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Boolean {
|
||||
And,
|
||||
Or,
|
||||
Xor,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Bits {
|
||||
BitOr,
|
||||
BitXor,
|
||||
|
@ -49,7 +49,7 @@ pub enum Bits {
|
|||
ShiftRight,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Assignment {
|
||||
Assign,
|
||||
PlusAssign,
|
||||
|
@ -59,7 +59,7 @@ pub enum Assignment {
|
|||
DivideAssign,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Operator {
|
||||
Comparison(Comparison),
|
||||
Math(Math),
|
||||
|
@ -170,7 +170,7 @@ pub fn eval_operator(op: &Expression) -> Result<Operator, ShellError> {
|
|||
Expression {
|
||||
expr: Expr::Operator(operator),
|
||||
..
|
||||
} => Ok(operator.clone()),
|
||||
} => Ok(*operator),
|
||||
Expression { span, expr, .. } => Err(ShellError::UnknownOperator {
|
||||
op_token: format!("{expr:?}"),
|
||||
span: *span,
|
||||
|
|
|
@ -111,25 +111,36 @@ pub enum ParseError {
|
|||
span: Span,
|
||||
},
|
||||
|
||||
#[error("{0} is not supported on values of type {3}")]
|
||||
#[diagnostic(code(nu::parser::unsupported_operation))]
|
||||
UnsupportedOperationLHS(
|
||||
String,
|
||||
#[label = "doesn't support this value"] Span,
|
||||
#[label("{3}")] Span,
|
||||
Type,
|
||||
),
|
||||
/// One or more of the values have types not supported by the operator.
|
||||
#[error("{op} is not supported on values of type {unsupported}.")]
|
||||
#[diagnostic(code(nu::parser::operator_unsupported_type))]
|
||||
OperatorUnsupportedType {
|
||||
op: &'static str,
|
||||
unsupported: Type,
|
||||
#[label = "does support this type"]
|
||||
op_span: Span,
|
||||
#[label("{unsupported}")]
|
||||
unsupported_span: Span,
|
||||
#[help]
|
||||
help: Option<&'static str>,
|
||||
},
|
||||
|
||||
#[error("{0} is not supported between {3} and {5}.")]
|
||||
#[diagnostic(code(nu::parser::unsupported_operation))]
|
||||
UnsupportedOperationRHS(
|
||||
String,
|
||||
#[label = "doesn't support these values"] Span,
|
||||
#[label("{3}")] Span,
|
||||
Type,
|
||||
#[label("{5}")] Span,
|
||||
Type,
|
||||
),
|
||||
/// The operator supports the types of both values, but not the specific combination of their types.
|
||||
#[error("{op} is not supported between types {lhs} and {rhs}.")]
|
||||
#[diagnostic(code(nu::parser::operator_type_mismatch))]
|
||||
OperatorTypeMismatch {
|
||||
op: &'static str,
|
||||
lhs: Type,
|
||||
rhs: Type,
|
||||
#[label = "does not operate between these two types"]
|
||||
op_span: Span,
|
||||
#[label("{lhs}")]
|
||||
lhs_span: Span,
|
||||
#[label("{rhs}")]
|
||||
rhs_span: Span,
|
||||
#[help]
|
||||
help: Option<&'static str>,
|
||||
},
|
||||
|
||||
#[error("{0} is not supported between {3}, {5}, and {7}.")]
|
||||
#[diagnostic(code(nu::parser::unsupported_operation))]
|
||||
|
@ -528,8 +539,8 @@ impl ParseError {
|
|||
ParseError::Expected(_, s) => *s,
|
||||
ParseError::ExpectedWithStringMsg(_, s) => *s,
|
||||
ParseError::Mismatch(_, _, s) => *s,
|
||||
ParseError::UnsupportedOperationLHS(_, _, s, _) => *s,
|
||||
ParseError::UnsupportedOperationRHS(_, _, _, _, s, _) => *s,
|
||||
ParseError::OperatorUnsupportedType { op_span, .. } => *op_span,
|
||||
ParseError::OperatorTypeMismatch { op_span, .. } => *op_span,
|
||||
ParseError::UnsupportedOperationTernary(_, _, _, _, _, _, s, _) => *s,
|
||||
ParseError::ExpectedKeyword(_, s) => *s,
|
||||
ParseError::UnexpectedKeyword(_, s) => *s,
|
||||
|
|
Loading…
Reference in a new issue