diff --git a/v1/topdown/binary.go b/v1/topdown/binary.go index 05050dbf7d..97cc2fef3e 100644 --- a/v1/topdown/binary.go +++ b/v1/topdown/binary.go @@ -10,7 +10,6 @@ import ( ) func builtinBinaryAnd(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error { - s1, err := builtins.SetOperand(operands[0].Value, 1) if err != nil { return err @@ -21,6 +20,10 @@ func builtinBinaryAnd(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Ter return err } + if s1.Len() == 0 || s2.Len() == 0 { + return iter(ast.InternedEmptySet) + } + i := s1.Intersect(s2) if i.Len() == 0 { return iter(ast.InternedEmptySet) @@ -30,7 +33,6 @@ func builtinBinaryAnd(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Ter } func builtinBinaryOr(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error { - s1, err := builtins.SetOperand(operands[0].Value, 1) if err != nil { return err @@ -41,6 +43,14 @@ func builtinBinaryOr(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term return err } + if s1.Len() == 0 { + return iter(operands[1]) + } + + if s2.Len() == 0 { + return iter(operands[0]) + } + return iter(ast.NewTerm(s1.Union(s2))) }