mirror of
https://github.com/nushell/nushell.git
synced 2025-03-29 17:16:49 +01:00
improve type inference
This commit is contained in:
parent
dda6554990
commit
739425431a
@ -182,9 +182,7 @@ fn eval_call(state: &State, call: &Call) -> Result<Value, ShellError> {
|
|||||||
})
|
})
|
||||||
} else if decl.signature.name == "vars" {
|
} else if decl.signature.name == "vars" {
|
||||||
state.parser_state.borrow().print_vars();
|
state.parser_state.borrow().print_vars();
|
||||||
Ok(Value::Nothing {
|
Ok(Value::Nothing { span: call.head })
|
||||||
span: call.positional[0].span,
|
|
||||||
})
|
|
||||||
} else if decl.signature.name == "decls" {
|
} else if decl.signature.name == "decls" {
|
||||||
state.parser_state.borrow().print_decls();
|
state.parser_state.borrow().print_decls();
|
||||||
Ok(Value::Nothing { span: call.head })
|
Ok(Value::Nothing { span: call.head })
|
||||||
|
@ -1784,6 +1784,8 @@ impl<'a> ParserWorkingSet<'a> {
|
|||||||
|
|
||||||
let mut args = vec![];
|
let mut args = vec![];
|
||||||
|
|
||||||
|
let mut contained_type: Option<Type> = None;
|
||||||
|
|
||||||
if !output.block.is_empty() {
|
if !output.block.is_empty() {
|
||||||
for arg in &output.block[0].commands {
|
for arg in &output.block[0].commands {
|
||||||
let mut spans_idx = 0;
|
let mut spans_idx = 0;
|
||||||
@ -1793,6 +1795,14 @@ impl<'a> ParserWorkingSet<'a> {
|
|||||||
self.parse_multispan_value(&arg.parts, &mut spans_idx, element_shape);
|
self.parse_multispan_value(&arg.parts, &mut spans_idx, element_shape);
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
|
|
||||||
|
if let Some(ref ctype) = contained_type {
|
||||||
|
if *ctype != arg.ty {
|
||||||
|
contained_type = Some(Type::Unknown);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
contained_type = Some(arg.ty.clone());
|
||||||
|
}
|
||||||
|
|
||||||
args.push(arg);
|
args.push(arg);
|
||||||
|
|
||||||
spans_idx += 1;
|
spans_idx += 1;
|
||||||
@ -1804,7 +1814,11 @@ impl<'a> ParserWorkingSet<'a> {
|
|||||||
Expression {
|
Expression {
|
||||||
expr: Expr::List(args),
|
expr: Expr::List(args),
|
||||||
span,
|
span,
|
||||||
ty: Type::List(Box::new(Type::Unknown)), // FIXME
|
ty: Type::List(Box::new(if let Some(ty) = contained_type {
|
||||||
|
ty.clone()
|
||||||
|
} else {
|
||||||
|
Type::Unknown
|
||||||
|
})),
|
||||||
},
|
},
|
||||||
error,
|
error,
|
||||||
)
|
)
|
||||||
@ -2416,6 +2430,16 @@ impl<'a> ParserWorkingSet<'a> {
|
|||||||
let (call, call_span, err) =
|
let (call, call_span, err) =
|
||||||
self.parse_internal_call(spans[0], &spans[1..], decl_id);
|
self.parse_internal_call(spans[0], &spans[1..], decl_id);
|
||||||
|
|
||||||
|
// Update the variable to the known type if we can.
|
||||||
|
if err.is_none() {
|
||||||
|
let var_id = call.positional[0]
|
||||||
|
.as_var()
|
||||||
|
.expect("internal error: expected variable");
|
||||||
|
let rhs_type = call.positional[1].ty.clone();
|
||||||
|
|
||||||
|
self.set_variable_type(var_id, rhs_type);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
Statement::Expression(Expression {
|
Statement::Expression(Expression {
|
||||||
expr: Expr::Call(call),
|
expr: Expr::Call(call),
|
||||||
|
Loading…
Reference in New Issue
Block a user