From ae05dc08765b8db8e149a56627cd29a878a0bce5 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 5 Oct 2021 19:45:38 +0200 Subject: Always use first positional argument in `expect()` This changes `#h(100)` from "missing argument: spacing" to "expected linear, found integer". --- src/eval/function.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/eval') diff --git a/src/eval/function.rs b/src/eval/function.rs index 205690df..d9f79adf 100644 --- a/src/eval/function.rs +++ b/src/eval/function.rs @@ -93,16 +93,21 @@ impl Args { None } - /// Find and consume the first castable positional argument, returning a - /// `missing argument: {what}` error if no match was found. + /// Try to cast the first positional argument ir returning a `missing + /// argument: {what}` error if no positional argument is left. pub fn expect(&mut self, what: &str) -> TypResult where T: Cast>, { - match self.eat() { - Some(found) => Ok(found), - None => bail!(self.span, "missing argument: {}", what), + for (i, slot) in self.items.iter().enumerate() { + if slot.name.is_none() { + let value = self.items.remove(i).value; + let span = value.span; + return T::cast(value).at(span); + } } + + bail!(self.span, "missing argument: {}", what); } /// Find and consume all castable positional arguments. -- cgit v1.2.3