pkg/encoding/yaml: validate concreteness instead of instance of for Validate

This makes the checks more permissive. Subsumption will
no longer be a part of the new evaluator, so we need to use
something different. Ultimately, the use of Subsumption here
is not ideal anyway, instead users should be able to specify
underspecified values in the type definitions itself.

Change-Id: I852bd4ebda805de3536ca33d4950dedcd379d835
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6462
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/testdata/script/vet_yaml.txt b/cmd/cue/cmd/testdata/script/vet_yaml.txt
index 7019b28..52347f7 100644
--- a/cmd/cue/cmd/testdata/script/vet_yaml.txt
+++ b/cmd/cue/cmd/testdata/script/vet_yaml.txt
@@ -2,11 +2,9 @@
 cmp stderr expect-stderr
 
 -- expect-stderr --
-phrases: error in call to encoding/yaml.Validate: missing field "text":
+phrases: error in call to encoding/yaml.Validate: phrases.quote1.text: incomplete value (!=""):
     ./yaml.cue:19:10
-    ./yaml.cue:4:11
     ./yaml.cue:11:17
-    yaml.Validate:4:6
 -- yaml.cue --
 import "encoding/yaml"
 
diff --git a/cue/builtin_test.go b/cue/builtin_test.go
index f65246b..a165a4c 100644
--- a/cue/builtin_test.go
+++ b/cue/builtin_test.go
@@ -115,13 +115,13 @@
 		`_|_(error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3))`,
 	}, {
 		test("encoding/yaml", `yaml.Validate("a: 2\n---\na: 4", {a:<3})`),
-		`_|_(error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3))`,
+		`_|_(error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3))`,
 	}, {
 		test("encoding/yaml", `yaml.Validate("a: 2\n---\na: 4", {a:<5})`),
 		`true`,
 	}, {
 		test("encoding/yaml", `yaml.Validate("a: 2\n", {a:<5, b:int})`),
-		`_|_(error in call to encoding/yaml.Validate: value not an instance)`,
+		`_|_(error in call to encoding/yaml.Validate: b: incomplete value (int))`,
 	}, {
 		test("encoding/yaml", `yaml.ValidatePartial("a: 2\n---\na: 4", {a:<3})`),
 		`_|_(error in call to encoding/yaml.ValidatePartial: a: invalid value 4 (out of bound <3))`,
diff --git a/cue/builtins.go b/cue/builtins.go
index 946d9d9..73b80eb 100644
--- a/cue/builtins.go
+++ b/cue/builtins.go
@@ -724,9 +724,14 @@
 								return false, err
 							}
 
-							if err := v.Subsume(inst.Value(), Final()); err != nil {
+							x := v.Unify(inst.Value())
+							if err := x.Err(); err != nil {
 								return false, err
 							}
+							if err := x.Validate(Concrete(true)); err != nil {
+								return false, err
+							}
+
 						}
 					}()
 				}
diff --git a/pkg/encoding/yaml/manual.go b/pkg/encoding/yaml/manual.go
index e35a060..6d60842 100644
--- a/pkg/encoding/yaml/manual.go
+++ b/pkg/encoding/yaml/manual.go
@@ -94,9 +94,23 @@
 			return false, err
 		}
 
-		if err := v.Subsume(inst.Value(), cue.Final()); err != nil {
+		// TODO: consider using subsumption again here.
+		// Alternatives:
+		// - allow definition of non-concrete list,
+		//   like list.Of(int), or []int.
+		// - Introduce ! in addition to ?, allowing:
+		//   list!: [...]
+		// if err := v.Subsume(inst.Value(), cue.Final()); err != nil {
+		// 	return false, err
+		// }
+		x := v.Unify(inst.Value())
+		if err := x.Err(); err != nil {
 			return false, err
 		}
+		if err := x.Validate(cue.Concrete(true)); err != nil {
+			return false, err
+		}
+
 	}
 }