mirror of
https://github.com/typst/typst
synced 2025-05-15 01:25:28 +08:00
Fix error priority for function arguments
Errors about superfluous arguments are now thrown before errors of the function execution itself. Fixes #1367
This commit is contained in:
parent
cbfd9884a9
commit
24a0bd8cfb
@ -307,6 +307,9 @@ fn create_wrapper_closure(func: &Func) -> TokenStream {
|
||||
}
|
||||
};
|
||||
|
||||
// Throws errors about unexpected arguments.
|
||||
let finish = (!func.special.args).then(|| quote! { args.take().finish()?; });
|
||||
|
||||
// This is the actual function call.
|
||||
let call = {
|
||||
let self_ = func
|
||||
@ -332,6 +335,7 @@ fn create_wrapper_closure(func: &Func) -> TokenStream {
|
||||
|vm, args| {
|
||||
let __typst_func = #parent #ident;
|
||||
#handlers
|
||||
#finish
|
||||
let output = #call;
|
||||
::typst::eval::IntoResult::into_result(output, args.span)
|
||||
}
|
||||
|
@ -313,6 +313,10 @@
|
||||
// Error: 2-26 cannot compare 3em with 2pt
|
||||
#(1pt, 2pt, 3em).sorted()
|
||||
|
||||
---
|
||||
// Error: 42-52 unexpected argument
|
||||
#((k: "a", v: 2), (k: "b", v: 1)).sorted(it => it.v)
|
||||
|
||||
---
|
||||
// Error: 2-18 array index out of bounds (index: -4, len: 3) and no default value was specified
|
||||
#(1, 2, 3).at(-4)
|
||||
|
Loading…
x
Reference in New Issue
Block a user