Improve "cannot apply '{+,-}'" error messages (#2510)

This commit is contained in:
MALO 2023-10-29 11:15:53 +01:00 committed by GitHub
parent 102a57056b
commit 500468fd05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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),
})
}

View File

@ -14,7 +14,7 @@
#test({2*}, 2)
---
// Error: 3-13 cannot apply '+' to content
// Error: 3-13 cannot apply unary '+' to content
#(+([] + []))
---