From 500468fd05a6aa893c534344f85dcffb551dec5d Mon Sep 17 00:00:00 2001 From: MALO <57839069+MDLC01@users.noreply.github.com> Date: Sun, 29 Oct 2023 11:15:53 +0100 Subject: [PATCH] Improve "cannot apply '{+,-}'" error messages (#2510) --- crates/typst/src/eval/ops.rs | 11 +++++++++++ tests/typ/compiler/ops-invalid.typ | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/typst/src/eval/ops.rs b/crates/typst/src/eval/ops.rs index 4a64cfed7..093eaa5f3 100644 --- a/crates/typst/src/eval/ops.rs +++ b/crates/typst/src/eval/ops.rs @@ -52,6 +52,16 @@ pub fn pos(value: Value) -> StrResult { Ratio(v) => Ratio(v), Relative(v) => Relative(v), Fraction(v) => Fraction(v), + Symbol(_) | Str(_) | Bytes(_) | Content(_) | Array(_) | Dict(_) | Datetime(_) => { + mismatch!("cannot apply unary '+' to {}", value) + } + Dyn(d) => { + if d.is::() { + mismatch!("cannot apply unary '+' to {}", d) + } else { + mismatch!("cannot apply '+' to {}", d) + } + } v => mismatch!("cannot apply '+' to {}", v), }) } @@ -67,6 +77,7 @@ pub fn neg(value: Value) -> StrResult { Relative(v) => Relative(-v), Fraction(v) => Fraction(-v), Duration(v) => Duration(-v), + Datetime(_) => mismatch!("cannot apply unary '-' to {}", value), v => mismatch!("cannot apply '-' to {}", v), }) } diff --git a/tests/typ/compiler/ops-invalid.typ b/tests/typ/compiler/ops-invalid.typ index 7e8b63eff..de8e62346 100644 --- a/tests/typ/compiler/ops-invalid.typ +++ b/tests/typ/compiler/ops-invalid.typ @@ -14,7 +14,7 @@ #test({2*}, 2) --- -// Error: 3-13 cannot apply '+' to content +// Error: 3-13 cannot apply unary '+' to content #(+([] + [])) ---