diff options
| author | MALO <57839069+MDLC01@users.noreply.github.com> | 2023-10-29 11:15:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-29 11:15:53 +0100 |
| commit | 500468fd05a6aa893c534344f85dcffb551dec5d (patch) | |
| tree | 180c8987aa6a3ec1df32dc994a39f58dc566e28e | |
| parent | 102a57056b41e3965a1acf528f17dd0c5e5ea673 (diff) | |
Improve "cannot apply '{+,-}'" error messages (#2510)
| -rw-r--r-- | crates/typst/src/eval/ops.rs | 11 | ||||
| -rw-r--r-- | tests/typ/compiler/ops-invalid.typ | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/crates/typst/src/eval/ops.rs b/crates/typst/src/eval/ops.rs index 4a64cfed..093eaa5f 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<Value> { 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::<Align>() { + 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<Value> { 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 7e8b63ef..de8e6234 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 #(+([] + [])) --- |
