Skip to content

Commit

Permalink
Fix comparisons with unions in runtime/sam/expr (#5210)
Browse files Browse the repository at this point in the history
Fix by calling zed.Value.Under in expr.Compare.Eval.
  • Loading branch information
nwt authored Aug 9, 2024
1 parent 54a5a15 commit ca81f72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions runtime/sam/expr/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ func (c *Compare) Eval(ectx Context, this zed.Value) zed.Value {
if rhs.IsError() {
return rhs
}
arena := ectx.Arena()
lhs, rhs = lhs.Under(arena), rhs.Under(arena)

if lhs.IsNull() {
if rhs.IsNull() {
Expand Down
9 changes: 9 additions & 0 deletions runtime/sam/expr/expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ func TestCompareNumbers(t *testing.T) {
testSuccessful(t, "u <= f", rec2, "false")
testSuccessful(t, "u > f", rec2, "true")
testSuccessful(t, "u >= f", rec2, "true")

// Test comparisons with unions.
const rec3 = "{l:1((int64,bytes)),r:2.((string,float64))}"
testSuccessful(t, "l == r", rec3, "false")
testSuccessful(t, "l != r", rec3, "true")
testSuccessful(t, "l < r", rec3, "true")
testSuccessful(t, "l <= r", rec3, "true")
testSuccessful(t, "l > r", rec3, "false")
testSuccessful(t, "l >= r", rec3, "false")
}

func TestCompareNonNumbers(t *testing.T) {
Expand Down

0 comments on commit ca81f72

Please sign in to comment.