diff --git a/runtime/expr/coerce/coerce.go b/runtime/expr/coerce/coerce.go index 6b97def0a0..1fc3a0634e 100644 --- a/runtime/expr/coerce/coerce.go +++ b/runtime/expr/coerce/coerce.go @@ -48,6 +48,7 @@ func (c *Pair) Equal() bool { } func (c *Pair) Coerce(a, b zed.Value) (int, error) { + a, b = a.Under(), b.Under() c.A = a.Bytes() c.B = b.Bytes() aid := a.Type().ID() diff --git a/runtime/expr/expr_test.go b/runtime/expr/expr_test.go index 86a1ad6a00..08916d6033 100644 --- a/runtime/expr/expr_test.go +++ b/runtime/expr/expr_test.go @@ -355,6 +355,14 @@ func TestArithmetic(t *testing.T) { testSuccessful(t, "f / 1.25", record, zed.NewFloat64(2.0)) testSuccessful(t, "5.0 / f", record, zed.NewFloat64(2.0)) + // Union values are dereferenced when doing arithmetic on them. + val := "10((int64,string))" + testSuccessful(t, "this + 1", val, zed.NewInt64(11)) + testSuccessful(t, "this - 1", val, zed.NewInt64(9)) + testSuccessful(t, "this * 2", val, zed.NewInt64(20)) + testSuccessful(t, "this / 2", val, zed.NewInt64(5)) + testSuccessful(t, "this % 3", val, zed.NewInt64(1)) + // Difference of two times is a duration testSuccessful(t, "a - b", "{a:2022-09-22T00:00:01Z,b:2022-09-22T00:00:00Z}", zed.NewDuration(nano.Second))