cue: workaround for empty "or" lists

See TODO for the proper solution.

Change-Id: I364dc0a8e30e77d9e046cd0f6b12907263ef906d
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3781
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/builtin.go b/cue/builtin.go
index 4ce6c57..7c667b7 100644
--- a/cue/builtin.go
+++ b/cue/builtin.go
@@ -192,7 +192,7 @@
 
 var orBuiltin = &builtin{
 	Name:   "or",
-	Params: []kind{stringKind | bytesKind | listKind | structKind},
+	Params: []kind{listKind},
 	Result: intKind,
 	Func: func(c *callCtxt) {
 		iter := c.iter(0)
@@ -202,7 +202,14 @@
 		}
 		c.ret = &disjunction{baseValue{c.src}, d, nil, false}
 		if len(d) == 0 {
-			c.ret = errors.New("empty list in call to or")
+			// TODO(manifest): This should not be unconditionally incomplete,
+			// but it requires results from comprehensions and all to have
+			// some special status. Mayb this can be solved by having results
+			// of list comprehensions be open if they result from iterating over
+			// an open list or struct. This would actually be exactly what
+			// that means. The error here could then only add an incomplete
+			// status if the source is open.
+			c.ret = c.ctx.mkErr(c.src, codeIncomplete, "empty list in call to or")
 		}
 	},
 }
diff --git a/cue/resolve_test.go b/cue/resolve_test.go
index b46ac22..b48d5e1 100644
--- a/cue/resolve_test.go
+++ b/cue/resolve_test.go
@@ -2556,6 +2556,23 @@
 		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)}`,
+	}, {
+		desc: "or builtin should not fail on non-concrete empty list",
+		in: `
+		Workflow :: {
+			jobs: {
+				<jobID>: {
+				}
+			}
+			JobID :: or([ k for k, _ in jobs ])
+		}
+
+		foo: Workflow & {
+			jobs foo: {
+			}
+		}
+		`,
+		out: `<0>{Workflow :: <1>C{jobs: <2>{<>: <3>(jobID: string)-><4>C{}, }, JobID :: or ([ <5>for k, _ in <6>.jobs yield <5>.k ])}, foo: <7>C{jobs: <8>{<>: <9>(jobID: string)-><10>C{}, foo: <11>C{}}, JobID :: "foo"}}`,
 	}}
 	rewriteHelper(t, testCases, evalFull)
 }