Skip to content

Commit

Permalink
internal/core: fail on missing required only when concrete
Browse files Browse the repository at this point in the history
In other case it is very much an incomplete error that should
be handled accordingly.

Also fixes a bug reporting issue where the error for a required
field that violates closedness did not get passed to the parent.

Fixes #2318

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Id3c629460e137a42fc7fe5dd44f05433c170d848
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/552185
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mpvl committed Apr 6, 2023
1 parent e7d7c6a commit f85172a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
15 changes: 15 additions & 0 deletions cmd/cue/cmd/testdata/script/vet_req.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
! exec cue vet in.cue
cmp stdout expect-stdout1
cmp stderr expect-stderr1

exec cue vet -c=false in.cue
cmp stdout expect-stdout2
cmp stderr expect-stderr2

-- in.cue --
x!: string
-- expect-stdout1 --
-- expect-stderr1 --
some instances are incomplete; use the -c flag to show errors or suppress this message
-- expect-stdout2 --
-- expect-stderr2 --
18 changes: 8 additions & 10 deletions cue/testdata/eval/required.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,8 @@ Unifications: 27
Conjuncts: 40
Disjuncts: 28
-- out/eval --
Errors:
self.t2.a: field is required but not present
unify.t2.p1.a: field is required but not present
unify.t2.p2.a: field is required but not present

Result:
(struct){
(_|_){
// [eval]
self: (struct){
t1: (struct){
a?: (int){ int }
Expand Down Expand Up @@ -149,9 +144,12 @@ Result:
a!: (int){ int }
}
}
allowed: (struct){
issue2306: (struct){
#A: (#struct){
allowed: (_|_){
// [eval]
issue2306: (_|_){
// [eval]
#A: (_|_){
// [eval]
a!: (_|_){
// [eval] allowed.issue2306.#A.a: field not allowed:
// ./in.cue:34:6
Expand Down
2 changes: 1 addition & 1 deletion internal/core/adt/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func (n *nodeContext) completeArcs(state vertexStatus) {

// Errors are allowed in let fields. Handle errors and failure to
// complete accordingly.
if !a.Label.IsLet() && a.ArcType == ArcMember {
if !a.Label.IsLet() && a.ArcType <= ArcRequired {
// Don't set the state to Finalized if the child arcs are not done.
if state == finalized && a.status < finalized {
state = conjuncts
Expand Down
2 changes: 1 addition & 1 deletion internal/core/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (v *validator) validate(x *adt.Vertex) {
}

for _, a := range x.Arcs {
if a.ArcType == adt.ArcRequired && v.inDefinition == 0 {
if a.ArcType == adt.ArcRequired && v.Concrete {
v.add(adt.NewRequiredNotPresentError(v.ctx, a))
continue
}
Expand Down

0 comments on commit f85172a

Please sign in to comment.