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 #(+([] + [])) ---