Skip to content

Commit

Permalink
internal/core/adt: required fields checked for closedness
Browse files Browse the repository at this point in the history
Unlike optional field constraints, required
field constraints do not result in a valid configuration
on error.

Fixes #2306

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I6f4d38a999b6e5ed49bb1629c479b0086bd78b06
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/552126
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 4, 2023
1 parent c67fe60 commit 42580d5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
48 changes: 41 additions & 7 deletions cue/testdata/eval/required.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ unify: t2: p2: {
#Def: t1: {
a!: int
}

allowed: issue2306: {
#A: a!: int
#A: #B

#B: b!: int
}
-- out/compile --
--- in.cue
{
Expand Down Expand Up @@ -81,17 +88,28 @@ unify: t2: p2: {
a!: int
}
}
allowed: {
issue2306: {
#A: {
a!: int
}
#A: 〈0;#B〉
#B: {
b!: int
}
}
}
}
-- out/eval/stats --
Leaks: 0
Freed: 20
Reused: 15
Allocs: 5
Retain: 0
Freed: 27
Reused: 21
Allocs: 6
Retain: 1

Unifications: 20
Conjuncts: 31
Disjuncts: 20
Unifications: 27
Conjuncts: 40
Disjuncts: 28
-- out/eval --
Errors:
self.t2.a: field is required but not present
Expand Down Expand Up @@ -131,4 +149,20 @@ Result:
a!: (int){ int }
}
}
allowed: (struct){
issue2306: (struct){
#A: (#struct){
a!: (_|_){
// [eval] allowed.issue2306.#A.a: field not allowed:
// ./in.cue:34:6
// ./in.cue:35:6
// ./in.cue:37:6
}
b!: (int){ int }
}
#B: (#struct){
b!: (int){ int }
}
}
}
}
2 changes: 1 addition & 1 deletion internal/core/adt/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ func (n *nodeContext) checkClosed(state vertexStatus) bool {
ignore := state != finalized || n.skipNonMonotonicChecks()

v := n.node
if !v.Label.IsInt() && v.Parent != nil && !ignore && v.isDefined() {
if !v.Label.IsInt() && v.Parent != nil && !ignore && v.ArcType <= ArcRequired {
ctx := n.ctx
// Visit arcs recursively to validate and compute error.
if _, err := verifyArc2(ctx, v.Label, v, v.Closed); err != nil {
Expand Down

0 comments on commit 42580d5

Please sign in to comment.