def argument check (#604)

* def argument check

* corrected test

* clippy error
This commit is contained in:
Fernando Herrera
2021-12-27 19:13:52 +00:00
committed by GitHub
parent 1837acfc70
commit 53330c5676
6 changed files with 116 additions and 127 deletions

View File

@ -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,