cue: Value.Expr: process or and and builtins semantically.

Fixes #928

Change-Id: I9db16a30931ab025272029e747ad26daefba526b
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9523
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/types.go b/cue/types.go
index f2627d0..009a179 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -2292,6 +2292,21 @@
 		a = append(a, remakeValue(v, env, x.Hi))
 		op = SliceOp
 	case *adt.CallExpr:
+		// Interpret "and" and "or" builtin semantically.
+		if fn, ok := x.Fun.(*adt.Builtin); ok && len(x.Args) == 1 &&
+			(fn.Name == "or" || fn.Name == "and") {
+
+			iter, _ := remakeValue(v, env, x.Args[0]).List()
+			for iter.Next() {
+				a = append(a, iter.Value())
+			}
+
+			op = OrOp
+			if fn.Name == "and" {
+				op = AndOp
+			}
+			break
+		}
 		a = append(a, remakeValue(v, env, x.Fun))
 		for _, arg := range x.Args {
 			a = append(a, remakeValue(v, env, arg))
diff --git a/cue/types_test.go b/cue/types_test.go
index 7954321..d5d613a 100644
--- a/cue/types_test.go
+++ b/cue/types_test.go
@@ -3326,6 +3326,12 @@
 	}, {
 		input: `v: [...number] | *[1, 2, 3]`,
 		want:  `([...number]|*[1,2,3])`,
+	}, {
+		input: `v: or([1, 2, 3])`,
+		want:  `|(1 2 3)`,
+	}, {
+		input: `v: and([1, 2, 3])`,
+		want:  `&(1 2 3)`,
 	}}
 	for _, tc := range testCases {
 		t.Run(tc.input, func(t *testing.T) {