cue: detect incomplete value for value method

Builtins should typically not accept incomplete values.
This was mostly detected, but not for the value method.

Fixes #234.

Change-Id: Ie51de9ca20b38fa13fce2c24ccf609a78f0d9e9f
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4387
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/builtin.go b/cue/builtin.go
index 2d5beca..bdad738 100644
--- a/cue/builtin.go
+++ b/cue/builtin.go
@@ -400,7 +400,13 @@
 }
 
 func (c *callCtxt) value(i int) Value {
-	return newValueRoot(c.ctx, c.args[i])
+	v := newValueRoot(c.ctx, c.args[i])
+	v, _ = v.Default()
+	if !v.IsConcrete() {
+		c.errf(c.src, v.toErr(c.ctx.mkErr(c.src, codeIncomplete,
+			"non-concrete value")), "incomplete")
+	}
+	return v
 }
 
 func (c *callCtxt) structVal(i int) *Struct {
diff --git a/cue/resolve_test.go b/cue/resolve_test.go
index d764502..def9e29 100644
--- a/cue/resolve_test.go
+++ b/cue/resolve_test.go
@@ -2845,6 +2845,15 @@
 			}
 			`,
 		out: `<0>{x: 1, y: <1>{x: 2, z: 1}}`,
+	}, {
+		desc: "don't pass incomplete values to builtins",
+		in: `
+		import "encoding/json"
+
+		input: string
+		foo: json.Marshal(input)
+		`,
+		out: `<0>{input: string, foo: <1>.Marshal (<2>.input)}`,
 	}}
 	rewriteHelper(t, testCases, evalFull)
 }