mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Allow adding none
and anything
This commit is contained in:
parent
204cad6bd6
commit
bc1bc91a33
@ -61,6 +61,9 @@ pub fn neg(value: Value) -> StrResult<Value> {
|
||||
/// Compute the sum of two values.
|
||||
pub fn add(lhs: Value, rhs: Value) -> StrResult<Value> {
|
||||
Ok(match (lhs, rhs) {
|
||||
(a, None) => a,
|
||||
(None, b) => b,
|
||||
|
||||
(Int(a), Int(b)) => Int(a + b),
|
||||
(Int(a), Float(b)) => Float(a as f64 + b),
|
||||
(Float(a), Int(b)) => Float(a + b as f64),
|
||||
@ -83,9 +86,6 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult<Value> {
|
||||
(Fraction(a), Fraction(b)) => Fraction(a + b),
|
||||
|
||||
(Str(a), Str(b)) => Str(a + b),
|
||||
|
||||
(Content(a), None) => Content(a),
|
||||
(None, Content(b)) => Content(b),
|
||||
(Content(a), Content(b)) => Content(a + b),
|
||||
(Content(a), Str(b)) => Content(a + model::Content::Text(b)),
|
||||
(Str(a), Content(b)) => Content(model::Content::Text(a) + b),
|
||||
|
@ -39,8 +39,8 @@
|
||||
// Missing lvalue is automatically none-initialized.
|
||||
{
|
||||
let dict = (:)
|
||||
// Error: 3-17 cannot add none and integer
|
||||
dict("b") += 1
|
||||
test(dict, (b: 1))
|
||||
}
|
||||
|
||||
---
|
||||
|
@ -27,6 +27,8 @@
|
||||
// Addition.
|
||||
#test(2 + 4, 6)
|
||||
#test("a" + "b", "ab")
|
||||
#test("a" + if false { "b" }, "a")
|
||||
#test("a" + if true { "b" }, "ab")
|
||||
#test(13 * "a" + "bbbbbb", "aaaaaaaaaaaaabbbbbb")
|
||||
#test((1, 2) + (3, 4), (1, 2, 3, 4))
|
||||
#test((a: 1) + (b: 2, c: 3), (a: 1, b: 2, c: 3))
|
||||
|
Loading…
x
Reference in New Issue
Block a user