forked from extern/nushell
def argument check (#604)
* def argument check * corrected test * clippy error
This commit is contained in:
@ -89,6 +89,25 @@ pub fn check_call(command: Span, sig: &Signature, call: &Call) -> Option<ParseEr
|
||||
}
|
||||
|
||||
if call.positional.len() < sig.required_positional.len() {
|
||||
// Comparing the types of all signature positional arguments against the parsed
|
||||
// expressions found in the call. If one type is not found then it could be assumed
|
||||
// that that positional argument is missing from the parsed call
|
||||
for argument in &sig.required_positional {
|
||||
let found = call.positional.iter().fold(false, |ac, expr| {
|
||||
if argument.shape.to_type() == expr.ty {
|
||||
true
|
||||
} else {
|
||||
ac
|
||||
}
|
||||
});
|
||||
if !found {
|
||||
return Some(ParseError::MissingPositional(
|
||||
argument.name.clone(),
|
||||
command,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let missing = &sig.required_positional[call.positional.len()];
|
||||
Some(ParseError::MissingPositional(missing.name.clone(), command))
|
||||
} else {
|
||||
@ -2075,7 +2094,7 @@ pub fn parse_signature(
|
||||
Expression {
|
||||
expr: Expr::Signature(sig),
|
||||
span,
|
||||
ty: Type::Unknown,
|
||||
ty: Type::Signature,
|
||||
custom_completion: None,
|
||||
},
|
||||
error,
|
||||
|
Reference in New Issue
Block a user