the sum operation now supports dicts too
This commit is contained in:
parent
4151f3f5e2
commit
efc92d434b
@ -26,6 +26,7 @@ func TestDictParser(t *testing.T) {
|
|||||||
/* 3 */ {`{1:"one",2:"two",3:"three"}`, map[int64]any{int64(1): "one", int64(2): "two", int64(3): "three"}, nil},
|
/* 3 */ {`{1:"one",2:"two",3:"three"}`, map[int64]any{int64(1): "one", int64(2): "two", int64(3): "three"}, nil},
|
||||||
/* 4 */ {`{1:"one",2:"two",3:"three"}.2`, "three", nil},
|
/* 4 */ {`{1:"one",2:"two",3:"three"}.2`, "three", nil},
|
||||||
/* 5 */ {`#{1:"one",2:"two",3:"three"}`, int64(3), nil},
|
/* 5 */ {`#{1:"one",2:"two",3:"three"}`, int64(3), nil},
|
||||||
|
/* 6 */ {`{1:"one"} + {2:"two"}`, map[any]any{1: "one", 2: "two"}, nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
succeeded := 0
|
succeeded := 0
|
||||||
|
@ -61,6 +61,14 @@ func evalPlus(ctx ExprContext, self *term) (v any, err error) {
|
|||||||
} else {
|
} else {
|
||||||
v, err = sumAnyFract(leftValue, rightValue)
|
v, err = sumAnyFract(leftValue, rightValue)
|
||||||
}
|
}
|
||||||
|
} else if IsDict(leftValue) && IsDict(rightValue) {
|
||||||
|
leftDict, _ := leftValue.(map[any]any)
|
||||||
|
rightDict, _ := rightValue.(map[any]any)
|
||||||
|
c := CloneMap(leftDict)
|
||||||
|
for key, value := range rightDict {
|
||||||
|
c[key] = value
|
||||||
|
}
|
||||||
|
v = c
|
||||||
} else {
|
} else {
|
||||||
err = self.errIncompatibleTypes(leftValue, rightValue)
|
err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user