Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cue: detect errors in struct when comparing to bottom
Browse files Browse the repository at this point in the history
Change-Id: Ie081b776e0e6e4e4bd45dd8a93f57a1a6f60ac90
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4302
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Dec 5, 2019
1 parent 279ca6a commit 630935e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cue/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ func (x *binaryExpr) evalPartial(ctx *context) (result evaluated) {
// evaluating to bottom don't evaluate to true. For now we check for
// bottom here and require that one of the values be a bottom literal.
if isLiteralBottom(x.left) || isLiteralBottom(x.right) {
if b := validate(ctx, left); b != nil {
left = b
}
if b := validate(ctx, right); b != nil {
right = b
}
leftBottom := isBottom(left)
rightBottom := isBottom(right)
switch x.op {
Expand Down
6 changes: 5 additions & 1 deletion cue/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2559,10 +2559,14 @@ func TestFullEval(t *testing.T) {
d: err != _|_ // allowed
e: err != 1&3
// z: err == err // TODO: should infer to be true?
f: ({a: 1} & {a: 2}) == _|_
g: ({a: 1} & {b: 2}) == _|_
h: _|_ == ({a: 1} & {a: 2})
i: _|_ == ({a: 1} & {b: 2})
err: 1 & 2
`,
out: `<0>{a: true, b: _|_((1 & 2):conflicting values 1 and 2), err: _|_((1 & 2):conflicting values 1 and 2), c: true, d: false, e: _|_((1 & 2):conflicting values 1 and 2)}`,
out: `<0>{a: true, b: _|_((1 & 2):conflicting values 1 and 2), err: _|_((1 & 2):conflicting values 1 and 2), c: true, d: false, e: _|_((1 & 2):conflicting values 1 and 2), f: true, g: false, h: true, i: false}`,
}, {
desc: "or builtin should not fail on non-concrete empty list",
in: `
Expand Down

0 comments on commit 630935e

Please sign in to comment.