cue: detect errors in struct when comparing to bottom

Change-Id: Ie081b776e0e6e4e4bd45dd8a93f57a1a6f60ac90
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4302
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/eval.go b/cue/eval.go
index f28a25a..0d2eb24 100644
--- a/cue/eval.go
+++ b/cue/eval.go
@@ -597,6 +597,12 @@
 		// evaluating to bottom don't evaluate to true. For now we check for
 		// bottom here and require that one of the values be a bottom literal.
 		if isLiteralBottom(x.left) || isLiteralBottom(x.right) {
+			if b := validate(ctx, left); b != nil {
+				left = b
+			}
+			if b := validate(ctx, right); b != nil {
+				right = b
+			}
 			leftBottom := isBottom(left)
 			rightBottom := isBottom(right)
 			switch x.op {
diff --git a/cue/resolve_test.go b/cue/resolve_test.go
index b2b1a1f..394490e 100644
--- a/cue/resolve_test.go
+++ b/cue/resolve_test.go
@@ -2559,10 +2559,14 @@
 		d: err != _|_ // allowed
 		e: err != 1&3
 		// z: err == err // TODO: should infer to be true?
+		f: ({a: 1} & {a: 2}) == _|_
+		g: ({a: 1} & {b: 2}) == _|_
+		h: _|_ == ({a: 1} & {a: 2})
+		i: _|_ == ({a: 1} & {b: 2})
 
 		err: 1 & 2
 		`,
-		out: `<0>{a: true, b: _|_((1 & 2):conflicting values 1 and 2), err: _|_((1 & 2):conflicting values 1 and 2), c: true, d: false, e: _|_((1 & 2):conflicting values 1 and 2)}`,
+		out: `<0>{a: true, b: _|_((1 & 2):conflicting values 1 and 2), err: _|_((1 & 2):conflicting values 1 and 2), c: true, d: false, e: _|_((1 & 2):conflicting values 1 and 2), f: true, g: false, h: true, i: false}`,
 	}, {
 		desc: "or builtin should not fail on non-concrete empty list",
 		in: `