diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index dc01bc14a2..ffe466e016 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -166,7 +166,7 @@ pub fn parse_for( Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, err, @@ -201,7 +201,7 @@ pub fn parse_for( Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, error, @@ -335,7 +335,7 @@ pub fn parse_def( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), err, @@ -393,7 +393,7 @@ pub fn parse_def( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), error, @@ -501,7 +501,7 @@ pub fn parse_extern( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), error, @@ -561,7 +561,7 @@ pub fn parse_alias( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), err, @@ -989,7 +989,7 @@ pub fn parse_export( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), exportable, @@ -1194,7 +1194,7 @@ pub fn parse_module( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), error, @@ -1244,7 +1244,7 @@ pub fn parse_use( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), err, @@ -1311,7 +1311,7 @@ pub fn parse_use( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), Some(ParseError::ModuleNotFound(spans[1])), @@ -1350,7 +1350,7 @@ pub fn parse_use( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), Some(ParseError::ModuleNotFound(spans[1])), @@ -1432,7 +1432,7 @@ pub fn parse_use( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), error, @@ -1473,7 +1473,7 @@ pub fn parse_hide( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), err, @@ -1640,7 +1640,7 @@ pub fn parse_hide( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), error, @@ -1725,7 +1725,7 @@ pub fn parse_let( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: nu_protocol::span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), error, @@ -1746,7 +1746,7 @@ pub fn parse_let( expressions: vec![Expression { expr: Expr::Call(call), span: nu_protocol::span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }], }, @@ -1790,7 +1790,7 @@ pub fn parse_source( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), error, @@ -1820,7 +1820,7 @@ pub fn parse_source( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: span(&spans[1..]), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), // Return the file parse error @@ -1837,7 +1837,7 @@ pub fn parse_source( call_with_block.positional.push(Expression { expr: Expr::Int(block_id as i64), span: spans[1], - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }); @@ -1845,7 +1845,7 @@ pub fn parse_source( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call_with_block), span: span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), None, @@ -1863,7 +1863,7 @@ pub fn parse_source( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), error, @@ -1932,7 +1932,7 @@ pub fn parse_register( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), err, @@ -2034,7 +2034,7 @@ pub fn parse_register( Pipeline::from_vec(vec![Expression { expr: Expr::Call(call), span: call_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }]), Some(err), diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 4d6f50dad7..d5dc6264ea 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -292,7 +292,7 @@ pub fn parse_external_call( Expression { expr: Expr::ExternalCall(head, args), span: span(spans), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, error, @@ -663,7 +663,7 @@ pub fn parse_multispan_value( Box::new(Expression::garbage(arg_span)), ), span: arg_span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, error, @@ -1008,7 +1008,7 @@ pub fn parse_call( Expression { expr: Expr::Call(call), span: span(spans), - ty: Type::Unknown, // FIXME: calls should have known output types + ty: Type::Any, // FIXME: calls should have known output types custom_completion: None, }, err, @@ -1615,7 +1615,7 @@ pub fn parse_variable_expr( Expression { expr: Expr::Var(nu_protocol::NU_VARIABLE_ID), span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, None, @@ -1625,7 +1625,7 @@ pub fn parse_variable_expr( Expression { expr: Expr::Var(nu_protocol::IN_VARIABLE_ID), span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, None, @@ -1635,7 +1635,7 @@ pub fn parse_variable_expr( Expression { expr: Expr::Var(nu_protocol::CONFIG_VARIABLE_ID), span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, None, @@ -1645,7 +1645,7 @@ pub fn parse_variable_expr( Expression { expr: Expr::Var(nu_protocol::ENV_VARIABLE_ID), span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, None, @@ -1782,7 +1782,7 @@ pub fn parse_full_cell_path( Expression { expr: Expr::Subexpression(block_id), span: head_span, - ty: Type::Unknown, // FIXME + ty: Type::Any, // FIXME custom_completion: None, }, true, @@ -1819,7 +1819,7 @@ pub fn parse_full_cell_path( Expression { expr: Expr::Var(var_id), span: Span::new(0, 0), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, false, @@ -1842,7 +1842,7 @@ pub fn parse_full_cell_path( ( Expression { expr: Expr::FullCellPath(Box::new(FullCellPath { head, tail })), - ty: Type::Unknown, + ty: Type::Any, span: full_cell_span, custom_completion: None, }, @@ -2565,11 +2565,11 @@ pub fn parse_type(_working_set: &StateWorkingSet, bytes: &[u8]) -> Type { b"date" => Type::Date, b"filesize" => Type::Filesize, b"number" => Type::Number, - b"table" => Type::Table, + b"table" => Type::Table(vec![]), //FIXME b"error" => Type::Error, b"binary" => Type::Binary, - _ => Type::Unknown, + _ => Type::Any, } } @@ -2746,13 +2746,13 @@ pub fn parse_var_with_opt_type( let id = working_set.add_variable( bytes[0..(bytes.len() - 1)].to_vec(), spans[*spans_idx], - Type::Unknown, + Type::Any, ); ( Expression { expr: Expr::VarDecl(id), span: spans[*spans_idx], - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, Some(ParseError::MissingType(spans[*spans_idx])), @@ -2763,23 +2763,20 @@ pub fn parse_var_with_opt_type( Expression { expr: Expr::Var(CONFIG_VARIABLE_ID), span: spans[*spans_idx], - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, None, ) } else { - let id = working_set.add_variable( - bytes, - span(&spans[*spans_idx..*spans_idx + 1]), - Type::Unknown, - ); + let id = + working_set.add_variable(bytes, span(&spans[*spans_idx..*spans_idx + 1]), Type::Any); ( Expression { expr: Expr::VarDecl(id), span: span(&spans[*spans_idx..*spans_idx + 1]), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, None, @@ -2812,7 +2809,7 @@ pub fn parse_row_condition( spans: &[Span], expand_aliases_denylist: &[usize], ) -> (Expression, Option) { - let var_id = working_set.add_variable(b"$it".to_vec(), span(spans), Type::Unknown); + let var_id = working_set.add_variable(b"$it".to_vec(), span(spans), Type::Any); let (expression, err) = parse_math_expression(working_set, spans, Some(var_id), expand_aliases_denylist); let span = span(spans); @@ -2973,7 +2970,7 @@ pub fn parse_signature_helper( let long = String::from_utf8_lossy(&flags[0][2..]).to_string(); let variable_name = flags[0][2..].to_vec(); let var_id = - working_set.add_variable(variable_name, span, Type::Unknown); + working_set.add_variable(variable_name, span, Type::Any); if flags.len() == 1 { args.push(Arg::Flag(Flag { @@ -3003,11 +3000,8 @@ pub fn parse_signature_helper( let chars: Vec = short_flag.chars().collect(); let long = String::from_utf8_lossy(&flags[0][2..]).to_string(); let variable_name = flags[0][2..].to_vec(); - let var_id = working_set.add_variable( - variable_name, - span, - Type::Unknown, - ); + let var_id = + working_set.add_variable(variable_name, span, Type::Any); if chars.len() == 1 { args.push(Arg::Flag(Flag { @@ -3042,7 +3036,7 @@ pub fn parse_signature_helper( let len = chars[0].encode_utf8(&mut encoded_var_name).len(); let variable_name = encoded_var_name[0..len].to_vec(); let var_id = - working_set.add_variable(variable_name, span, Type::Unknown); + working_set.add_variable(variable_name, span, Type::Any); args.push(Arg::Flag(Flag { arg: None, @@ -3100,8 +3094,7 @@ pub fn parse_signature_helper( let contents: Vec<_> = contents[..(contents.len() - 1)].into(); let name = String::from_utf8_lossy(&contents).to_string(); - let var_id = - working_set.add_variable(contents, span, Type::Unknown); + let var_id = working_set.add_variable(contents, span, Type::Any); // Positional arg, optional args.push(Arg::Positional( @@ -3119,7 +3112,7 @@ pub fn parse_signature_helper( let contents_vec: Vec = contents.to_vec(); let var_id = - working_set.add_variable(contents_vec, span, Type::Unknown); + working_set.add_variable(contents_vec, span, Type::Any); args.push(Arg::RestPositional(PositionalArg { desc: String::new(), @@ -3133,7 +3126,7 @@ pub fn parse_signature_helper( let contents_vec = contents.to_vec(); let var_id = - working_set.add_variable(contents_vec, span, Type::Unknown); + working_set.add_variable(contents_vec, span, Type::Any); // Positional arg, required args.push(Arg::Positional( @@ -3200,7 +3193,7 @@ pub fn parse_signature_helper( let var_id = var_id.expect("internal error: all custom parameters must have var_ids"); let var_type = &working_set.get_variable(var_id).ty; match var_type { - Type::Unknown => { + Type::Any => { working_set.set_variable_type( var_id, expression.ty.clone(), @@ -3248,7 +3241,7 @@ pub fn parse_signature_helper( // Flags with a boolean type are just present/not-present switches if var_type != &Type::Bool { match var_type { - Type::Unknown => { + Type::Any => { *arg = Some(expression_ty.to_shape()); working_set .set_variable_type(var_id, expression_ty); @@ -3403,7 +3396,7 @@ pub fn parse_list_expression( if let Some(ref ctype) = contained_type { if *ctype != arg.ty { - contained_type = Some(Type::Unknown); + contained_type = Some(Type::Any); } } else { contained_type = Some(arg.ty.clone()); @@ -3423,7 +3416,7 @@ pub fn parse_list_expression( ty: Type::List(Box::new(if let Some(ty) = contained_type { ty } else { - Type::Unknown + Type::Any })), custom_completion: None, }, @@ -3466,7 +3459,7 @@ pub fn parse_table_expression( Expression { expr: Expr::List(vec![]), span: original_span, - ty: Type::List(Box::new(Type::Unknown)), + ty: Type::List(Box::new(Type::Any)), custom_completion: None, }, None, @@ -3538,7 +3531,7 @@ pub fn parse_table_expression( Expression { expr: Expr::Table(table_headers, rows), span: original_span, - ty: Type::Table, + ty: Type::Table(vec![]), //FIXME custom_completion: None, }, error, @@ -3995,7 +3988,7 @@ pub fn parse_operator( Expression { expr: Expr::Operator(operator), span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, None, @@ -4403,7 +4396,7 @@ pub fn parse_expression( Expression { expr: Expr::List(env_vars), span: span(&spans[..pos]), - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }, Expression { @@ -4428,7 +4421,7 @@ pub fn parse_expression( expr, custom_completion: None, span: span(spans), - ty: Type::Unknown, + ty: Type::Any, }, err, ) @@ -4575,7 +4568,7 @@ pub fn parse_record( Expression { expr: Expr::Record(output), span, - ty: Type::Unknown, //FIXME: but we don't know the contents of the fields, do we? + ty: Type::Any, //FIXME: but we don't know the contents of the fields, do we? custom_completion: None, }, error, @@ -4989,7 +4982,7 @@ fn wrap_expr_with_collect(working_set: &mut StateWorkingSet, expr: &Expression) output.push(Expression { expr: Expr::Block(block_id), span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, }); diff --git a/crates/nu-parser/src/type_check.rs b/crates/nu-parser/src/type_check.rs index 22184e239c..8d9cf20fa2 100644 --- a/crates/nu-parser/src/type_check.rs +++ b/crates/nu-parser/src/type_check.rs @@ -10,8 +10,8 @@ pub fn type_compatible(lhs: &Type, rhs: &Type) -> bool { (Type::List(c), Type::List(d)) => type_compatible(c, d), (Type::Number, Type::Int) => true, (Type::Number, Type::Float) => true, - (Type::Unknown, _) => true, - (_, Type::Unknown) => true, + (Type::Any, _) => true, + (_, Type::Any) => true, (lhs, rhs) => lhs == rhs, } } @@ -35,13 +35,13 @@ pub fn math_result_type( (Type::Duration, Type::Duration) => (Type::Duration, None), (Type::Filesize, Type::Filesize) => (Type::Filesize, None), - (Type::Unknown, _) => (Type::Unknown, None), - (_, Type::Unknown) => (Type::Unknown, None), + (Type::Any, _) => (Type::Any, None), + (_, Type::Any) => (Type::Any, None), (Type::Int, _) => { let ty = rhs.ty.clone(); *rhs = Expression::garbage(rhs.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -54,7 +54,7 @@ pub fn math_result_type( _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -74,12 +74,12 @@ pub fn math_result_type( (Type::Duration, Type::Duration) => (Type::Duration, None), (Type::Filesize, Type::Filesize) => (Type::Filesize, None), - (Type::Unknown, _) => (Type::Unknown, None), - (_, Type::Unknown) => (Type::Unknown, None), + (Type::Any, _) => (Type::Any, None), + (_, Type::Any) => (Type::Any, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -101,12 +101,12 @@ pub fn math_result_type( (Type::Duration, Type::Int) => (Type::Filesize, None), (Type::Int, Type::Duration) => (Type::Filesize, None), - (Type::Unknown, _) => (Type::Unknown, None), - (_, Type::Unknown) => (Type::Unknown, None), + (Type::Any, _) => (Type::Any, None), + (_, Type::Any) => (Type::Any, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -123,12 +123,12 @@ pub fn math_result_type( (Type::Int, Type::Float) => (Type::Float, None), (Type::Float, Type::Float) => (Type::Float, None), - (Type::Unknown, _) => (Type::Unknown, None), - (_, Type::Unknown) => (Type::Unknown, None), + (Type::Any, _) => (Type::Any, None), + (_, Type::Any) => (Type::Any, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -150,12 +150,12 @@ pub fn math_result_type( (Type::Filesize, Type::Int) => (Type::Filesize, None), (Type::Duration, Type::Int) => (Type::Duration, None), - (Type::Unknown, _) => (Type::Unknown, None), - (_, Type::Unknown) => (Type::Unknown, None), + (Type::Any, _) => (Type::Any, None), + (_, Type::Any) => (Type::Any, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -169,12 +169,12 @@ pub fn math_result_type( Operator::And | Operator::Or => match (&lhs.ty, &rhs.ty) { (Type::Bool, Type::Bool) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Unknown, None), - (_, Type::Unknown) => (Type::Unknown, None), + (Type::Any, _) => (Type::Any, None), + (_, Type::Any) => (Type::Any, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -193,12 +193,12 @@ pub fn math_result_type( (Type::Duration, Type::Duration) => (Type::Bool, None), (Type::Filesize, Type::Filesize) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Bool, None), - (_, Type::Unknown) => (Type::Bool, None), + (Type::Any, _) => (Type::Bool, None), + (_, Type::Any) => (Type::Bool, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -217,12 +217,12 @@ pub fn math_result_type( (Type::Duration, Type::Duration) => (Type::Bool, None), (Type::Filesize, Type::Filesize) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Bool, None), - (_, Type::Unknown) => (Type::Bool, None), + (Type::Any, _) => (Type::Bool, None), + (_, Type::Any) => (Type::Bool, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -241,12 +241,12 @@ pub fn math_result_type( (Type::Duration, Type::Duration) => (Type::Bool, None), (Type::Filesize, Type::Filesize) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Bool, None), - (_, Type::Unknown) => (Type::Bool, None), + (Type::Any, _) => (Type::Bool, None), + (_, Type::Any) => (Type::Bool, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -265,12 +265,12 @@ pub fn math_result_type( (Type::Duration, Type::Duration) => (Type::Bool, None), (Type::Filesize, Type::Filesize) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Bool, None), - (_, Type::Unknown) => (Type::Bool, None), + (Type::Any, _) => (Type::Bool, None), + (_, Type::Any) => (Type::Bool, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -285,12 +285,12 @@ pub fn math_result_type( Operator::NotEqual => (Type::Bool, None), Operator::Contains => match (&lhs.ty, &rhs.ty) { (Type::String, Type::String) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Bool, None), - (_, Type::Unknown) => (Type::Bool, None), + (Type::Any, _) => (Type::Bool, None), + (_, Type::Any) => (Type::Bool, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -303,12 +303,12 @@ pub fn math_result_type( }, Operator::NotContains => match (&lhs.ty, &rhs.ty) { (Type::String, Type::String) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Bool, None), - (_, Type::Unknown) => (Type::Bool, None), + (Type::Any, _) => (Type::Bool, None), + (_, Type::Any) => (Type::Bool, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -321,12 +321,12 @@ pub fn math_result_type( }, Operator::StartsWith => match (&lhs.ty, &rhs.ty) { (Type::String, Type::String) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Bool, None), - (_, Type::Unknown) => (Type::Bool, None), + (Type::Any, _) => (Type::Bool, None), + (_, Type::Any) => (Type::Bool, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -343,12 +343,12 @@ pub fn math_result_type( (Type::String, Type::String) => (Type::Bool, None), (Type::String, Type::Record(_)) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Bool, None), - (_, Type::Unknown) => (Type::Bool, None), + (Type::Any, _) => (Type::Bool, None), + (_, Type::Any) => (Type::Bool, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -365,12 +365,12 @@ pub fn math_result_type( (Type::String, Type::String) => (Type::Bool, None), (Type::String, Type::Record(_)) => (Type::Bool, None), - (Type::Unknown, _) => (Type::Bool, None), - (_, Type::Unknown) => (Type::Bool, None), + (Type::Any, _) => (Type::Bool, None), + (_, Type::Any) => (Type::Bool, None), _ => { *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::UnsupportedOperation( op.span, lhs.span, @@ -386,7 +386,7 @@ pub fn math_result_type( *op = Expression::garbage(op.span); ( - Type::Unknown, + Type::Any, Some(ParseError::IncompleteMathExpression(op.span)), ) } diff --git a/crates/nu-protocol/src/ast/expression.rs b/crates/nu-protocol/src/ast/expression.rs index a0c4d034f1..b0e92fec7f 100644 --- a/crates/nu-protocol/src/ast/expression.rs +++ b/crates/nu-protocol/src/ast/expression.rs @@ -18,7 +18,7 @@ impl Expression { Expression { expr: Expr::Garbage, span, - ty: Type::Unknown, + ty: Type::Any, custom_completion: None, } } diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index bf870a8b1d..a017779389 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -192,11 +192,11 @@ impl EngineState { files: im::vector![], file_contents: im::vector![], vars: im::vector![ - Variable::new(Span::new(0, 0), Type::Unknown), - Variable::new(Span::new(0, 0), Type::Unknown), - Variable::new(Span::new(0, 0), Type::Unknown), - Variable::new(Span::new(0, 0), Type::Unknown), - Variable::new(Span::new(0, 0), Type::Unknown) + Variable::new(Span::new(0, 0), Type::Any), + Variable::new(Span::new(0, 0), Type::Any), + Variable::new(Span::new(0, 0), Type::Any), + Variable::new(Span::new(0, 0), Type::Any), + Variable::new(Span::new(0, 0), Type::Any) ], decls: im::vector![], aliases: im::vector![], diff --git a/crates/nu-protocol/src/syntax_shape.rs b/crates/nu-protocol/src/syntax_shape.rs index ebc8d5c51d..645bc9ca9e 100644 --- a/crates/nu-protocol/src/syntax_shape.rs +++ b/crates/nu-protocol/src/syntax_shape.rs @@ -96,37 +96,37 @@ pub enum SyntaxShape { impl SyntaxShape { pub fn to_type(&self) -> Type { match self { - SyntaxShape::Any => Type::Unknown, + SyntaxShape::Any => Type::Any, SyntaxShape::Block(_) => Type::Block, SyntaxShape::Binary => Type::Binary, - SyntaxShape::CellPath => Type::Unknown, + SyntaxShape::CellPath => Type::Any, SyntaxShape::Custom(custom, _) => custom.to_type(), SyntaxShape::DateTime => Type::Date, SyntaxShape::Duration => Type::Duration, - SyntaxShape::Expression => Type::Unknown, + SyntaxShape::Expression => Type::Any, SyntaxShape::Filepath => Type::String, SyntaxShape::Filesize => Type::Filesize, - SyntaxShape::FullCellPath => Type::Unknown, + SyntaxShape::FullCellPath => Type::Any, SyntaxShape::GlobPattern => Type::String, - SyntaxShape::ImportPattern => Type::Unknown, + SyntaxShape::ImportPattern => Type::Any, SyntaxShape::Int => Type::Int, SyntaxShape::List(x) => { let contents = x.to_type(); Type::List(Box::new(contents)) } SyntaxShape::Keyword(_, expr) => expr.to_type(), - SyntaxShape::MathExpression => Type::Unknown, + SyntaxShape::MathExpression => Type::Any, SyntaxShape::Number => Type::Number, - SyntaxShape::Operator => Type::Unknown, - SyntaxShape::Range => Type::Unknown, + SyntaxShape::Operator => Type::Any, + SyntaxShape::Range => Type::Any, SyntaxShape::Record => Type::Record(vec![]), // FIXME: Add actual record type SyntaxShape::RowCondition => Type::Bool, SyntaxShape::Boolean => Type::Bool, SyntaxShape::Signature => Type::Signature, SyntaxShape::String => Type::String, - SyntaxShape::Table => Type::List(Box::new(Type::Unknown)), // FIXME: Tables should have better types - SyntaxShape::VarWithOptType => Type::Unknown, - SyntaxShape::Variable => Type::Unknown, + SyntaxShape::Table => Type::List(Box::new(Type::Any)), // FIXME: Tables should have better types + SyntaxShape::VarWithOptType => Type::Any, + SyntaxShape::Variable => Type::Any, } } } diff --git a/crates/nu-protocol/src/ty.rs b/crates/nu-protocol/src/ty.rs index 8ce822d7a0..58455120c3 100644 --- a/crates/nu-protocol/src/ty.rs +++ b/crates/nu-protocol/src/ty.rs @@ -20,9 +20,9 @@ pub enum Type { Number, Nothing, Record(Vec<(String, Type)>), - Table, + Table(Vec<(String, Type)>), ListStream, - Unknown, + Any, Error, Binary, Custom, @@ -46,9 +46,9 @@ impl Type { Type::Number => SyntaxShape::Number, Type::Nothing => SyntaxShape::Any, Type::Record(_) => SyntaxShape::Record, - Type::Table => SyntaxShape::Table, + Type::Table(_) => SyntaxShape::Table, Type::ListStream => SyntaxShape::List(Box::new(SyntaxShape::Any)), - Type::Unknown => SyntaxShape::Any, + Type::Any => SyntaxShape::Any, Type::Error => SyntaxShape::Any, Type::Binary => SyntaxShape::Binary, Type::Custom => SyntaxShape::Any, @@ -78,13 +78,21 @@ impl Display for Type { .collect::>() .join(", "), ), - Type::Table => write!(f, "table"), + Type::Table(columns) => write!( + f, + "table<{}>", + columns + .iter() + .map(|(x, y)| format!("{}: {}", x, y)) + .collect::>() + .join(", ") + ), Type::List(l) => write!(f, "list<{}>", l), Type::Nothing => write!(f, "nothing"), Type::Number => write!(f, "number"), Type::String => write!(f, "string"), Type::ListStream => write!(f, "list stream"), - Type::Unknown => write!(f, "unknown"), + Type::Any => write!(f, "any"), Type::Error => write!(f, "error"), Type::Binary => write!(f, "binary"), Type::Custom => write!(f, "custom"), diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index af03af0ee6..382f3685ba 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -378,7 +378,26 @@ impl Value { .map(|(x, y)| (x.clone(), y.get_type())) .collect(), ), - Value::List { .. } => Type::List(Box::new(Type::Unknown)), // FIXME + Value::List { vals, .. } => { + let mut ty = None; + for val in vals { + let val_ty = val.get_type(); + match &ty { + Some(x) => { + if &val_ty != x { + ty = Some(Type::Any) + } + } + None => ty = Some(val_ty), + } + } + + match ty { + Some(Type::Record(columns)) => Type::Table(columns), + Some(ty) => Type::List(Box::new(ty)), + None => Type::List(Box::new(ty.unwrap_or(Type::Any))), + } + } Value::Nothing { .. } => Type::Nothing, Value::Block { .. } => Type::Block, Value::Error { .. } => Type::Error, @@ -1735,8 +1754,8 @@ impl Value { } if !type_compatible(self.get_type(), rhs.get_type()) - && (self.get_type() != Type::Unknown) - && (rhs.get_type() != Type::Unknown) + && (self.get_type() != Type::Any) + && (rhs.get_type() != Type::Any) { return Err(ShellError::TypeMismatch("compatible type".to_string(), op)); } @@ -1763,8 +1782,8 @@ impl Value { } if !type_compatible(self.get_type(), rhs.get_type()) - && (self.get_type() != Type::Unknown) - && (rhs.get_type() != Type::Unknown) + && (self.get_type() != Type::Any) + && (rhs.get_type() != Type::Any) { return Err(ShellError::TypeMismatch("compatible type".to_string(), op)); } @@ -1791,8 +1810,8 @@ impl Value { } if !type_compatible(self.get_type(), rhs.get_type()) - && (self.get_type() != Type::Unknown) - && (rhs.get_type() != Type::Unknown) + && (self.get_type() != Type::Any) + && (rhs.get_type() != Type::Any) { return Err(ShellError::TypeMismatch("compatible type".to_string(), op)); } @@ -1819,8 +1838,8 @@ impl Value { } if !type_compatible(self.get_type(), rhs.get_type()) - && (self.get_type() != Type::Unknown) - && (rhs.get_type() != Type::Unknown) + && (self.get_type() != Type::Any) + && (rhs.get_type() != Type::Any) { return Err(ShellError::TypeMismatch("compatible type".to_string(), op)); }