Skip to content

Commit

Permalink
internal/core/adt: get default when comparing ot bottom
Browse files Browse the repository at this point in the history
This is a good example that comparison to bottom is broken:
this was a bug, but should an ambiguous disjunction be an
error or not? We really need more specific builtins.

Fixes #809

Change-Id: Ia856b331dca67864421759b493f446fd0be76b29
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8902
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Mar 5, 2021
1 parent 7326cfa commit 1589a07
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
76 changes: 76 additions & 0 deletions cue/testdata/comprehensions/iferror.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ incomplete: {
x
}
}

// Issue #809
useDefault: {
a: {
x: *"foo" | string
if x != _|_ {
y: x
}
}

issue809: {
#A: {
a: string
b: *a | string
}

s: [Name=string]: #A & { a: Name }
s: bar: _

foo: [
for _, a in s if a.b != _|_ {a},
]
}
}

-- out/compile --
--- in.cue
{
Expand Down Expand Up @@ -57,6 +82,33 @@ incomplete: {
〈1;x〉
}
}
useDefault: {
a: {
x: (*"foo"|string)
if (〈0;x〉 != _|_(explicit error (_|_ literal) in source)) {
y: 〈1;x〉
}
}
issue809: {
#A: {
a: string
b: (*〈0;a〉|string)
}
s: {
[string]: (〈1;#A〉 & {
a: 〈1;-〉
})
}
s: {
bar: _
}
foo: [
for _, a in 〈0;s〉 if (〈0;a〉.b != _|_(explicit error (_|_ literal) in source)) {
〈1;a〉
},
]
}
}
}
-- out/eval --
Errors:
Expand Down Expand Up @@ -91,4 +143,28 @@ Result:
2: (int){ 3 }
}
}
useDefault: (struct){
a: (struct){
x: (string){ |(*(string){ "foo" }, (string){ string }) }
y: (string){ |(*(string){ "foo" }, (string){ string }) }
}
issue809: (struct){
#A: (#struct){
a: (string){ string }
b: (string){ string }
}
s: (struct){
bar: (#struct){
a: (string){ "bar" }
b: (string){ |(*(string){ "bar" }, (string){ string }) }
}
}
foo: (#list){
0: (#struct){
a: (string){ "bar" }
b: (string){ |(*(string){ "bar" }, (string){ string }) }
}
}
}
}
}
3 changes: 1 addition & 2 deletions internal/core/adt/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,11 +1157,10 @@ func (c *OpContext) validate(env *Environment, src ast.Node, x Expr, op Op) (r V
}

var match bool
v := c.evalState(x, Partial)
// NOTE: using Unwrap is maybe note entirely accurate, as it may discard
// a future error. However, if it does so, the error will at least be
// reported elsewhere.
switch b := Unwrap(v).(type) {
switch b := c.value(x).(type) {
case nil:
case *Bottom:
if b.Code == CycleError {
Expand Down

0 comments on commit 1589a07

Please sign in to comment.