Skip to content

Commit 57f8242

Browse files
committed
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 <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 21ca371 commit 57f8242

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

cmd/cue/cmd/testdata/script/vet_yaml.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
cmp stderr expect-stderr
33

44
-- expect-stderr --
5-
phrases: error in call to encoding/yaml.Validate: missing field "text":
5+
phrases: error in call to encoding/yaml.Validate: phrases.quote1.text: incomplete value (!=""):
66
./yaml.cue:19:10
7-
./yaml.cue:4:11
87
./yaml.cue:11:17
9-
yaml.Validate:4:6
108
-- yaml.cue --
119
import "encoding/yaml"
1210

cue/builtin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ func TestBuiltins(t *testing.T) {
115115
`_|_(error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3))`,
116116
}, {
117117
test("encoding/yaml", `yaml.Validate("a: 2\n---\na: 4", {a:<3})`),
118-
`_|_(error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3))`,
118+
`_|_(error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3))`,
119119
}, {
120120
test("encoding/yaml", `yaml.Validate("a: 2\n---\na: 4", {a:<5})`),
121121
`true`,
122122
}, {
123123
test("encoding/yaml", `yaml.Validate("a: 2\n", {a:<5, b:int})`),
124-
`_|_(error in call to encoding/yaml.Validate: value not an instance)`,
124+
`_|_(error in call to encoding/yaml.Validate: b: incomplete value (int))`,
125125
}, {
126126
test("encoding/yaml", `yaml.ValidatePartial("a: 2\n---\na: 4", {a:<3})`),
127127
`_|_(error in call to encoding/yaml.ValidatePartial: a: invalid value 4 (out of bound <3))`,

cue/builtins.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/encoding/yaml/manual.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,23 @@ func Validate(b []byte, v cue.Value) (bool, error) {
9494
return false, err
9595
}
9696

97-
if err := v.Subsume(inst.Value(), cue.Final()); err != nil {
97+
// TODO: consider using subsumption again here.
98+
// Alternatives:
99+
// - allow definition of non-concrete list,
100+
// like list.Of(int), or []int.
101+
// - Introduce ! in addition to ?, allowing:
102+
// list!: [...]
103+
// if err := v.Subsume(inst.Value(), cue.Final()); err != nil {
104+
// return false, err
105+
// }
106+
x := v.Unify(inst.Value())
107+
if err := x.Err(); err != nil {
98108
return false, err
99109
}
110+
if err := x.Validate(cue.Concrete(true)); err != nil {
111+
return false, err
112+
}
113+
100114
}
101115
}
102116

0 commit comments

Comments
 (0)