mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 04:45:04 +02:00
Remove dfr from dataframe commands (#5760)
* input and output tests * input and output types for dfr * expression converter * remove deprecated command * correct expressions * cargo clippy * identifier for ls * cargo clippy * type for head and tail expression * modify full cell path if block
This commit is contained in:
@ -21,7 +21,7 @@ use crate::{
|
||||
parser::{
|
||||
check_call, check_name, garbage, garbage_pipeline, parse, parse_block_expression,
|
||||
parse_internal_call, parse_multispan_value, parse_signature, parse_string,
|
||||
parse_var_with_opt_type, trim_quotes,
|
||||
parse_var_with_opt_type, trim_quotes, ParsedInternalCall,
|
||||
},
|
||||
unescape_unquote_string, ParseError,
|
||||
};
|
||||
@ -127,13 +127,18 @@ pub fn parse_for(
|
||||
}
|
||||
Some(decl_id) => {
|
||||
working_set.enter_scope();
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
decl_id,
|
||||
expand_aliases_denylist,
|
||||
);
|
||||
|
||||
working_set.exit_scope();
|
||||
|
||||
let call_span = span(spans);
|
||||
@ -165,7 +170,7 @@ pub fn parse_for(
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
},
|
||||
err,
|
||||
@ -296,13 +301,18 @@ pub fn parse_def(
|
||||
}
|
||||
Some(decl_id) => {
|
||||
working_set.enter_scope();
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
decl_id,
|
||||
expand_aliases_denylist,
|
||||
);
|
||||
|
||||
working_set.exit_scope();
|
||||
|
||||
let call_span = span(spans);
|
||||
@ -334,7 +344,7 @@ pub fn parse_def(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
err,
|
||||
@ -439,7 +449,9 @@ pub fn parse_extern(
|
||||
}
|
||||
Some(decl_id) => {
|
||||
working_set.enter_scope();
|
||||
let (call, err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call, error: err, ..
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
@ -521,7 +533,7 @@ pub fn parse_alias(
|
||||
}
|
||||
|
||||
if let Some(decl_id) = working_set.find_decl(b"alias", &Type::Any) {
|
||||
let (call, _) = parse_internal_call(
|
||||
let ParsedInternalCall { call, output, .. } = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
@ -534,7 +546,7 @@ pub fn parse_alias(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: span(spans),
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
None,
|
||||
@ -1243,7 +1255,11 @@ pub fn parse_use(
|
||||
|
||||
let (call, call_span, use_decl_id) = match working_set.find_decl(b"use", &Type::Any) {
|
||||
Some(decl_id) => {
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
@ -1260,7 +1276,7 @@ pub fn parse_use(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
err,
|
||||
@ -1476,7 +1492,11 @@ pub fn parse_hide(
|
||||
|
||||
let (call, call_span, hide_decl_id) = match working_set.find_decl(b"hide", &Type::Any) {
|
||||
Some(decl_id) => {
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
@ -1493,7 +1513,7 @@ pub fn parse_hide(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
err,
|
||||
@ -1701,7 +1721,11 @@ pub fn parse_overlay(
|
||||
// TODO: Abstract this code blob, it's repeated all over the place:
|
||||
let call = match working_set.find_decl(b"overlay list", &Type::Any) {
|
||||
Some(decl_id) => {
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
span(&spans[..2]),
|
||||
if spans.len() > 2 { &spans[2..] } else { &[] },
|
||||
@ -1718,7 +1742,7 @@ pub fn parse_overlay(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
err,
|
||||
@ -1760,7 +1784,11 @@ pub fn parse_overlay(
|
||||
|
||||
let call = match working_set.find_decl(b"overlay", &Type::Any) {
|
||||
Some(decl_id) => {
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
@ -1777,7 +1805,7 @@ pub fn parse_overlay(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
err,
|
||||
@ -1825,7 +1853,11 @@ pub fn parse_overlay_new(
|
||||
|
||||
let (call, call_span) = match working_set.find_decl(b"overlay new", &Type::Any) {
|
||||
Some(decl_id) => {
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
span(&spans[0..2]),
|
||||
&spans[2..],
|
||||
@ -1842,7 +1874,7 @@ pub fn parse_overlay_new(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
err,
|
||||
@ -1916,7 +1948,11 @@ pub fn parse_overlay_add(
|
||||
// TODO: Allow full import pattern as argument (requires custom naming of module/overlay)
|
||||
let (call, call_span) = match working_set.find_decl(b"overlay add", &Type::Any) {
|
||||
Some(decl_id) => {
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
span(&spans[0..2]),
|
||||
&spans[2..],
|
||||
@ -1933,7 +1969,7 @@ pub fn parse_overlay_add(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
err,
|
||||
@ -2103,7 +2139,11 @@ pub fn parse_overlay_remove(
|
||||
|
||||
let call = match working_set.find_decl(b"overlay remove", &Type::Any) {
|
||||
Some(decl_id) => {
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
span(&spans[0..2]),
|
||||
&spans[2..],
|
||||
@ -2120,7 +2160,7 @@ pub fn parse_overlay_remove(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
err,
|
||||
@ -2247,7 +2287,6 @@ pub fn parse_let(
|
||||
error = error.or(err);
|
||||
|
||||
let var_id = lvalue.as_var();
|
||||
|
||||
let rhs_type = rvalue.ty.clone();
|
||||
|
||||
if let Some(var_id) = var_id {
|
||||
@ -2277,7 +2316,11 @@ pub fn parse_let(
|
||||
}
|
||||
}
|
||||
}
|
||||
let (call, err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
@ -2290,7 +2333,7 @@ pub fn parse_let(
|
||||
expressions: vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: nu_protocol::span(spans),
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}],
|
||||
},
|
||||
@ -2320,7 +2363,11 @@ pub fn parse_source(
|
||||
let cwd = working_set.get_cwd();
|
||||
// Is this the right call to be using here?
|
||||
// Some of the others (`parse_let`) use it, some of them (`parse_hide`) don't.
|
||||
let (call, err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
@ -2334,7 +2381,7 @@ pub fn parse_source(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: span(spans),
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
error,
|
||||
@ -2459,7 +2506,11 @@ pub fn parse_register(
|
||||
)
|
||||
}
|
||||
Some(decl_id) => {
|
||||
let (call, mut err) = parse_internal_call(
|
||||
let ParsedInternalCall {
|
||||
call,
|
||||
error: mut err,
|
||||
output,
|
||||
} = parse_internal_call(
|
||||
working_set,
|
||||
spans[0],
|
||||
&spans[1..],
|
||||
@ -2476,7 +2527,7 @@ pub fn parse_register(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
span: call_span,
|
||||
ty: Type::Any,
|
||||
ty: output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
err,
|
||||
|
@ -724,13 +724,19 @@ pub fn parse_multispan_value(
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ParsedInternalCall {
|
||||
pub call: Box<Call>,
|
||||
pub output: Type,
|
||||
pub error: Option<ParseError>,
|
||||
}
|
||||
|
||||
pub fn parse_internal_call(
|
||||
working_set: &mut StateWorkingSet,
|
||||
command_span: Span,
|
||||
spans: &[Span],
|
||||
decl_id: usize,
|
||||
expand_aliases_denylist: &[usize],
|
||||
) -> (Box<Call>, Option<ParseError>) {
|
||||
) -> ParsedInternalCall {
|
||||
trace!("parsing: internal call (decl id: {})", decl_id);
|
||||
|
||||
let mut error = None;
|
||||
@ -742,7 +748,8 @@ pub fn parse_internal_call(
|
||||
let decl = working_set.get_decl(decl_id);
|
||||
let signature = decl.signature();
|
||||
let output = decl.output_type();
|
||||
working_set.found_outputs.push(output);
|
||||
|
||||
working_set.type_scope.add_type(output.clone());
|
||||
|
||||
if signature.creates_scope {
|
||||
working_set.enter_scope();
|
||||
@ -925,8 +932,11 @@ pub fn parse_internal_call(
|
||||
working_set.exit_scope();
|
||||
}
|
||||
|
||||
// FIXME: output type unknown
|
||||
(Box::new(call), error)
|
||||
ParsedInternalCall {
|
||||
call: Box::new(call),
|
||||
output,
|
||||
error,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_call(
|
||||
@ -1012,7 +1022,7 @@ pub fn parse_call(
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
let input = working_set.found_outputs.last().unwrap_or(&Type::Any);
|
||||
let input = working_set.type_scope.get_previous();
|
||||
let mut maybe_decl_id = working_set.find_decl(&name, input);
|
||||
|
||||
while maybe_decl_id.is_none() {
|
||||
@ -1060,21 +1070,22 @@ pub fn parse_call(
|
||||
trace!("parsing: internal call");
|
||||
|
||||
// parse internal command
|
||||
let (call, err) = parse_internal_call(
|
||||
let parsed_call = parse_internal_call(
|
||||
working_set,
|
||||
span(&spans[cmd_start..pos]),
|
||||
&spans[pos..],
|
||||
decl_id,
|
||||
expand_aliases_denylist,
|
||||
);
|
||||
|
||||
(
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
expr: Expr::Call(parsed_call.call),
|
||||
span: span(spans),
|
||||
ty: Type::Any, // FIXME: calls should have known output types
|
||||
ty: parsed_call.output,
|
||||
custom_completion: None,
|
||||
},
|
||||
err,
|
||||
parsed_call.error,
|
||||
)
|
||||
} else {
|
||||
// We might be parsing left-unbounded range ("..10")
|
||||
@ -1853,8 +1864,14 @@ pub fn parse_full_cell_path(
|
||||
let (output, err) = lite_parse(&output);
|
||||
error = error.or(err);
|
||||
|
||||
// Creating a Type scope to parse the new block. This will keep track of
|
||||
// the previous input type found in that block
|
||||
let (output, err) =
|
||||
parse_block(working_set, &output, true, expand_aliases_denylist, true);
|
||||
working_set
|
||||
.type_scope
|
||||
.add_type(working_set.type_scope.get_last_output());
|
||||
|
||||
error = error.or(err);
|
||||
|
||||
let block_id = working_set.add_block(output);
|
||||
@ -1864,7 +1881,7 @@ pub fn parse_full_cell_path(
|
||||
Expression {
|
||||
expr: Expr::Subexpression(block_id),
|
||||
span: head_span,
|
||||
ty: Type::Any, // FIXME
|
||||
ty: working_set.type_scope.get_last_output(),
|
||||
custom_completion: None,
|
||||
},
|
||||
true,
|
||||
@ -1929,8 +1946,8 @@ pub fn parse_full_cell_path(
|
||||
if !tail.is_empty() {
|
||||
(
|
||||
Expression {
|
||||
ty: head.ty.clone(), // FIXME. How to access the last type of tail?
|
||||
expr: Expr::FullCellPath(Box::new(FullCellPath { head, tail })),
|
||||
ty: Type::Any,
|
||||
span: full_cell_span,
|
||||
custom_completion: None,
|
||||
},
|
||||
@ -4581,6 +4598,9 @@ pub fn parse_variable(
|
||||
|
||||
if is_variable(bytes) {
|
||||
if let Some(var_id) = working_set.find_variable(bytes) {
|
||||
let input = working_set.get_variable(var_id).ty.clone();
|
||||
working_set.type_scope.add_type(input);
|
||||
|
||||
(Some(var_id), None)
|
||||
} else {
|
||||
(None, None)
|
||||
@ -4612,19 +4632,20 @@ pub fn parse_builtin_commands(
|
||||
b"source" => parse_source(working_set, &lite_command.parts, expand_aliases_denylist),
|
||||
b"export" => {
|
||||
if let Some(decl_id) = working_set.find_decl(b"alias", &Type::Any) {
|
||||
let (call, _) = parse_internal_call(
|
||||
let parsed_call = parse_internal_call(
|
||||
working_set,
|
||||
lite_command.parts[0],
|
||||
&lite_command.parts[1..],
|
||||
decl_id,
|
||||
expand_aliases_denylist,
|
||||
);
|
||||
if call.has_flag("help") {
|
||||
|
||||
if parsed_call.call.has_flag("help") {
|
||||
(
|
||||
Pipeline::from_vec(vec![Expression {
|
||||
expr: Expr::Call(call),
|
||||
expr: Expr::Call(parsed_call.call),
|
||||
span: span(&lite_command.parts),
|
||||
ty: Type::Any,
|
||||
ty: parsed_call.output,
|
||||
custom_completion: None,
|
||||
}]),
|
||||
None,
|
||||
@ -4759,6 +4780,7 @@ pub fn parse_block(
|
||||
if scoped {
|
||||
working_set.enter_scope();
|
||||
}
|
||||
working_set.type_scope.enter_scope();
|
||||
|
||||
let mut error = None;
|
||||
|
||||
@ -4789,6 +4811,8 @@ pub fn parse_block(
|
||||
let (expr, err) =
|
||||
parse_expression(working_set, &command.parts, expand_aliases_denylist);
|
||||
|
||||
working_set.type_scope.add_type(expr.ty.clone());
|
||||
|
||||
if error.is_none() {
|
||||
error = err;
|
||||
}
|
||||
@ -4872,6 +4896,7 @@ pub fn parse_block(
|
||||
if scoped {
|
||||
working_set.exit_scope();
|
||||
}
|
||||
working_set.type_scope.exit_scope();
|
||||
|
||||
(block, error)
|
||||
}
|
||||
|
@ -35,6 +35,9 @@ pub fn math_result_type(
|
||||
(Type::Duration, Type::Duration) => (Type::Duration, None),
|
||||
(Type::Filesize, Type::Filesize) => (Type::Filesize, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Any, None),
|
||||
(_, Type::Any) => (Type::Any, None),
|
||||
(Type::Int, _) => {
|
||||
@ -74,6 +77,9 @@ pub fn math_result_type(
|
||||
(Type::Duration, Type::Duration) => (Type::Duration, None),
|
||||
(Type::Filesize, Type::Filesize) => (Type::Filesize, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Any, None),
|
||||
(_, Type::Any) => (Type::Any, None),
|
||||
_ => {
|
||||
@ -101,6 +107,9 @@ pub fn math_result_type(
|
||||
(Type::Duration, Type::Int) => (Type::Filesize, None),
|
||||
(Type::Int, Type::Duration) => (Type::Filesize, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Any, None),
|
||||
(_, Type::Any) => (Type::Any, None),
|
||||
_ => {
|
||||
@ -123,6 +132,9 @@ pub fn math_result_type(
|
||||
(Type::Int, Type::Float) => (Type::Float, None),
|
||||
(Type::Float, Type::Float) => (Type::Float, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Any, None),
|
||||
(_, Type::Any) => (Type::Any, None),
|
||||
_ => {
|
||||
@ -150,6 +162,9 @@ pub fn math_result_type(
|
||||
(Type::Filesize, Type::Int) => (Type::Filesize, None),
|
||||
(Type::Duration, Type::Int) => (Type::Duration, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Any, None),
|
||||
(_, Type::Any) => (Type::Any, None),
|
||||
_ => {
|
||||
@ -169,6 +184,9 @@ pub fn math_result_type(
|
||||
Operator::And | Operator::Or => match (&lhs.ty, &rhs.ty) {
|
||||
(Type::Bool, Type::Bool) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Any, None),
|
||||
(_, Type::Any) => (Type::Any, None),
|
||||
_ => {
|
||||
@ -193,6 +211,9 @@ pub fn math_result_type(
|
||||
(Type::Duration, Type::Duration) => (Type::Bool, None),
|
||||
(Type::Filesize, Type::Filesize) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
_ => {
|
||||
@ -217,6 +238,9 @@ pub fn math_result_type(
|
||||
(Type::Duration, Type::Duration) => (Type::Bool, None),
|
||||
(Type::Filesize, Type::Filesize) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
_ => {
|
||||
@ -241,6 +265,9 @@ pub fn math_result_type(
|
||||
(Type::Duration, Type::Duration) => (Type::Bool, None),
|
||||
(Type::Filesize, Type::Filesize) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
_ => {
|
||||
@ -265,6 +292,9 @@ pub fn math_result_type(
|
||||
(Type::Duration, Type::Duration) => (Type::Bool, None),
|
||||
(Type::Filesize, Type::Filesize) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
_ => {
|
||||
@ -281,12 +311,26 @@ pub fn math_result_type(
|
||||
)
|
||||
}
|
||||
},
|
||||
Operator::Equal => (Type::Bool, None),
|
||||
Operator::NotEqual => (Type::Bool, None),
|
||||
Operator::Equal => match (&lhs.ty, &rhs.ty) {
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
_ => (Type::Bool, None),
|
||||
},
|
||||
Operator::NotEqual => match (&lhs.ty, &rhs.ty) {
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
_ => (Type::Bool, None),
|
||||
},
|
||||
Operator::RegexMatch => match (&lhs.ty, &rhs.ty) {
|
||||
(Type::String, Type::String) => (Type::Bool, None),
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
_ => {
|
||||
*op = Expression::garbage(op.span);
|
||||
(
|
||||
@ -305,6 +349,10 @@ pub fn math_result_type(
|
||||
(Type::String, Type::String) => (Type::Bool, None),
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
_ => {
|
||||
*op = Expression::garbage(op.span);
|
||||
(
|
||||
@ -323,6 +371,10 @@ pub fn math_result_type(
|
||||
(Type::String, Type::String) => (Type::Bool, None),
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
_ => {
|
||||
*op = Expression::garbage(op.span);
|
||||
(
|
||||
@ -341,6 +393,10 @@ pub fn math_result_type(
|
||||
(Type::String, Type::String) => (Type::Bool, None),
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
_ => {
|
||||
*op = Expression::garbage(op.span);
|
||||
(
|
||||
@ -361,6 +417,9 @@ pub fn math_result_type(
|
||||
(Type::String, Type::String) => (Type::Bool, None),
|
||||
(Type::String, Type::Record(_)) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
_ => {
|
||||
@ -383,6 +442,9 @@ pub fn math_result_type(
|
||||
(Type::String, Type::String) => (Type::Bool, None),
|
||||
(Type::String, Type::Record(_)) => (Type::Bool, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.to_string()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Bool, None),
|
||||
(_, Type::Any) => (Type::Bool, None),
|
||||
_ => {
|
||||
|
Reference in New Issue
Block a user