Skip to content

Commit

Permalink
internal/core/validate: use defaults in concrete mode
Browse files Browse the repository at this point in the history
Change-Id: Ib9275fe6bfccc272d142b853ae7b6d6555a63098
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6654
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jul 23, 2020
1 parent f159888 commit 765f87e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 8 additions & 6 deletions internal/core/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ func (v *validator) validate(x *adt.Vertex) {
return
}

} else if v.Concrete && v.inDefinition == 0 && !adt.IsConcrete(x) {
// TODO: use ValueError to get full path.
v.add(&adt.Bottom{
Code: adt.IncompleteError,
Err: v.ctx.Newf("incomplete value %v", v.ctx.Str(x.Value)),
})
} else if v.Concrete && v.inDefinition == 0 {
x := x.Default()
if !adt.IsConcrete(x) {
v.add(&adt.Bottom{
Code: adt.IncompleteError,
Err: v.ctx.Newf("incomplete value %v", v.ctx.Str(x.Value)),
})
}
}

for _, a := range x.Arcs {
Expand Down
6 changes: 6 additions & 0 deletions internal/core/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ y: incompatible values 4 and 2`,
x: 1 & 2
`,
out: "eval\nx: incompatible values 2 and 1",
}, {
desc: "consider defaults for concreteness",
cfg: &Config{Concrete: true},
in: `
x: *1 | 2
`,
}}

r := runtime.New()
Expand Down

0 comments on commit 765f87e

Please sign in to comment.