cue: fix detection of incomplete value

The issue was that validation would not descent into a list, as
values where not complete, while simultaneously the groundness
check would not detect incomplete errors.

Also hoisted v.ctx() to make code a bit more debugger friendly.

Closes #324.

Change-Id: I053619085d311c10d66e073e758de1b4c6d6a7c8
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5422
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/testdata/script/issue324.txt b/cmd/cue/cmd/testdata/script/issue324.txt
new file mode 100644
index 0000000..4cf9287
--- /dev/null
+++ b/cmd/cue/cmd/testdata/script/issue324.txt
@@ -0,0 +1,13 @@
+! cue vet foo.cue
+
+cmp stderr expect-stderr
+
+-- foo.cue --
+import "encoding/yaml"
+
+x: string
+a: b: c: *["\(x)"] | _
+d: yaml.Marshal(a.b)
+
+-- expect-stderr --
+some instances are incomplete; use the -c flag to show errors or suppress this message
diff --git a/cue/types.go b/cue/types.go
index 06e8c35..7481905 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -1910,7 +1910,8 @@
 		}
 	}
 	if o.concrete {
-		if err := isGroundRecursive(v.ctx(), v.eval(v.ctx())); err != nil {
+		ctx := v.ctx()
+		if err := isGroundRecursive(ctx, v.eval(ctx)); err != nil {
 			x.errs = errors.Append(x.errs, v.toErr(err))
 		}
 	}
@@ -1963,6 +1964,10 @@
 
 func isGroundRecursive(ctx *context, v value) *bottom {
 	switch x := v.(type) {
+	case *bottom:
+		if isIncomplete(x) {
+			return x
+		}
 	case *list:
 		for i := 0; i < len(x.elem.arcs); i++ {
 			v := ctx.manifest(x.at(ctx, i))
diff --git a/cue/types_test.go b/cue/types_test.go
index bb173e4..a4c7b0b 100644
--- a/cue/types_test.go
+++ b/cue/types_test.go
@@ -1318,6 +1318,15 @@
 		instance1: Schema1
 		`,
 		opts: []Option{Concrete(true)},
+	}, {
+		desc: "issue324",
+		in: `
+		import "encoding/yaml"
+
+		x: string
+		a: b: c: *["\(x)"] | _
+		d: yaml.Marshal(a.b)
+		`,
 	}}
 	for _, tc := range testCases {
 		t.Run(tc.desc, func(t *testing.T) {