summaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-10-05 19:45:38 +0200
committerLaurenz <laurmaedje@gmail.com>2021-10-05 19:45:38 +0200
commitae05dc08765b8db8e149a56627cd29a878a0bce5 (patch)
tree36a45bb9308784d514d6cb8aa1d257440e213686 /src/eval
parent0a23bfbc23ec68ed229b78c8f9995928c133c4a6 (diff)
Always use first positional argument in `expect()`
This changes `#h(100)` from "missing argument: spacing" to "expected linear, found integer".
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/function.rs15
1 files changed, 10 insertions, 5 deletions
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<T>(&mut self, what: &str) -> TypResult<T>
where
T: Cast<Spanned<Value>>,
{
- 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.