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

Commit

Permalink
internal/core/adt: fix bug that left errors of incompleted expression…
Browse files Browse the repository at this point in the history
…s unreported

This also requires simplification of BoundExpr to simulate
complete cycle handling.

Fixes #475
Fixes #680
Fixes #684

Change-Id: I906d8cc6e3689abb74c7c1ebc2ba96ecd98aaf4c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8323
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jan 28, 2021
1 parent 8334a9e commit c091274
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 31 deletions.
8 changes: 6 additions & 2 deletions cue/testdata/builtins/incomplete.txtar
Expand Up @@ -79,9 +79,13 @@ value2: {
// [incomplete] list2.#Sub: undefined field b:
// ./in.cue:30:13
}
Out2: (list){
Out2: (_|_){
// [incomplete] list2.#Sub: undefined field b:
// ./in.cue:30:13
}
Out3: (list){
Out3: (_|_){
// [incomplete] list2.#Sub: undefined field b:
// ./in.cue:30:13
}
_Top: (_|_){
// [incomplete] list2.#Sub: undefined field b:
Expand Down
Expand Up @@ -186,7 +186,10 @@ Result:
}
xc1: (int){ |((int){ 8 }, (int){ 9 }) }
xc2: (int){ 8 }
xc3: (int){ 6 }
xc3: (_|_){
// [incomplete] xc3: unresolved disjunction 8 | 9 (type int):
// ./in.cue:29:10
}
xc4: (int){ 9 }
xc5: (int){ 10 }
xd1: (int){ 8 }
Expand Down Expand Up @@ -235,5 +238,8 @@ Result:
}
z1: (int){ |((int){ 11 }, (int){ 13 }) }
z2: (int){ 10 }
z3: (int){ 8 }
z3: (_|_){
// [incomplete] z3: unresolved disjunction 11 | 13 (type int):
// ./in.cue:58:5
}
}
171 changes: 170 additions & 1 deletion cue/testdata/eval/bounds.txtar
Expand Up @@ -10,8 +10,67 @@ b4: >=20 & >20
b5: >=21 & >20
b6: int & >5 & <= 6

simplifyExpr: {
less1: <(<3)
less2: <(<=3)
less3: <=(<3)
less4: <=(<=3)
less5: <(!=3)
less6: <=(!=3)

gtr1: >(>3)
gtr2: >(>=3)
gtr3: >=(>3)
gtr4: >=(>=3)
gtr5: >(!=3)
gtr6: >=(!=3)

lg1: <(>3)
lg2: <(>=3)
lg3: <=(>3)
lg4: <=(>=3)

gl1: >(<3)
gl2: >(<=3)
gl3: >=(<3)
gl4: >=(<=3)

ne1: !=(!=3)
ne2: !=(<3)
ne3: !=(<=3)
ne4: !=(>3)
ne5: !=(>=3)

s: string
n: number
i: int
f: float
b: bytes
basic1: <(i)
basic2: >(n)
basic3: >=(s)
basic4: <=(f)
basic5: <=(b)

// Do NOT interpret this the same as `!= type`.
bne1: !=(s)
bne2: !=(n)
bne3: !=(n)
bne4: !=(i)
bne5: !=(b)

e1: <(=~"foo")
e2: >(null)
}

-- out/eval --
(struct){
Errors:
simplifyExpr.e2: cannot use null for bound >:
./in.cue:62:11

Result:
(_|_){
// [eval]
x0: (int){ 5 }
x1: (int){ 30 }
b0: (number){ &(>0, <5) }
Expand All @@ -21,6 +80,72 @@ b6: int & >5 & <= 6
b4: (number){ >20 }
b5: (number){ >=21 }
b6: (int){ 6 }
simplifyExpr: (_|_){
// [eval]
less1: (number){ <3 }
less2: (number){ <3 }
less3: (number){ <3 }
less4: (number){ <=3 }
less5: (number){ number }
less6: (number){ number }
gtr1: (number){ >3 }
gtr2: (number){ >3 }
gtr3: (number){ >3 }
gtr4: (number){ >=3 }
gtr5: (number){ number }
gtr6: (number){ number }
lg1: (number){ number }
lg2: (number){ number }
lg3: (number){ number }
lg4: (number){ number }
gl1: (number){ number }
gl2: (number){ number }
gl3: (number){ number }
gl4: (number){ number }
ne1: (int){ 3 }
ne2: (number){ >=3 }
ne3: (number){ >3 }
ne4: (number){ <=3 }
ne5: (number){ <3 }
s: (string){ string }
n: (number){ number }
i: (int){ int }
f: (float){ float }
b: (bytes){ bytes }
basic1: (int){ int }
basic2: (number){ number }
basic3: (string){ string }
basic4: (float){ float }
basic5: (bytes){ bytes }
bne1: (_|_){
// [incomplete] simplifyExpr.bne1: non-concrete value s for bound !=:
// ./in.cue:55:11
}
bne2: (_|_){
// [incomplete] simplifyExpr.bne2: non-concrete value n for bound !=:
// ./in.cue:56:11
}
bne3: (_|_){
// [incomplete] simplifyExpr.bne3: non-concrete value n for bound !=:
// ./in.cue:57:11
}
bne4: (_|_){
// [incomplete] simplifyExpr.bne4: non-concrete value i for bound !=:
// ./in.cue:58:11
}
bne5: (_|_){
// [incomplete] simplifyExpr.bne5: non-concrete value b for bound !=:
// ./in.cue:59:11
}
e1: (_|_){
// [incomplete] simplifyExpr.e1: non-concrete value =~"foo" for bound <:
// ./in.cue:61:9
}
e2: (_|_){
// [eval] simplifyExpr.e2: cannot use null for bound >:
// ./in.cue:62:11
}
}
}
-- out/compile --
--- in.cue
Expand All @@ -34,4 +159,48 @@ b6: int & >5 & <= 6
b4: (>=20 & >20)
b5: (>=21 & >20)
b6: ((int & >5) & <=6)
simplifyExpr: {
less1: <<3
less2: <<=3
less3: <=<3
less4: <=<=3
less5: <!=3
less6: <=!=3
gtr1: >>3
gtr2: >>=3
gtr3: >=>3
gtr4: >=>=3
gtr5: >!=3
gtr6: >=!=3
lg1: <>3
lg2: <>=3
lg3: <=>3
lg4: <=>=3
gl1: ><3
gl2: ><=3
gl3: >=<3
gl4: >=<=3
ne1: !=!=3
ne2: !=<3
ne3: !=<=3
ne4: !=>3
ne5: !=>=3
s: string
n: number
i: int
f: float
b: bytes
basic1: <〈0;i〉
basic2: >〈0;n〉
basic3: >=〈0;s〉
basic4: <=〈0;f〉
basic5: <=〈0;b〉
bne1: !=〈0;s〉
bne2: !=〈0;n〉
bne3: !=〈0;n〉
bne4: !=〈0;i〉
bne5: !=〈0;b〉
e1: <=~"foo"
e2: >null
}
}
5 changes: 4 additions & 1 deletion cue/testdata/eval/errunifiy.txtar
Expand Up @@ -15,7 +15,10 @@ explicit error (_|_ literal) in source:
Result:
(_|_){
// [user]
a: (string){ "t" }
a: (_|_){
// [incomplete] empty list in call to or:
// ./in.cue:1:4
}
b: (_|_){
// [user] explicit error (_|_ literal) in source:
// ./in.cue:4:4
Expand Down
33 changes: 22 additions & 11 deletions cue/testdata/eval/incomplete.txtar
@@ -1,11 +1,12 @@
These should all be an incomplete errors.
These should all be incomplete errors.

-- in.cue --
s: string

e1: s + s
e2: >"bar" & s // TODO
e3: >s & "foo" // TODO
e2: >"bar" & s // okay
e3: >s & "foo" // okay
e3b: >s

e4: >e1 & s
e5: <e5 & s
Expand All @@ -22,10 +23,13 @@ permanentlyIncompleteOperands: {
a: "golang/go:1.13.5"
}

issue680: (>10 * 2) & 0


-- out/eval --
Errors:
permanentlyIncompleteOperands.a: invalid operand string ('+' requires concrete value):
./in.cue:18:8
./in.cue:19:8

Result:
(_|_){
Expand All @@ -37,39 +41,44 @@ Result:
}
e2: (string){ >"bar" }
e3: (string){ "foo" }
e3b: (string){ string }
e4: (_|_){
// [incomplete] e1: non-concrete value string in operand to +:
// ./in.cue:3:5
}
e5: (_|_){
// [cycle] cycle error:
// ./in.cue:8:6
// ./in.cue:9:6
}
E: (struct){
a: (_|_){
// [cycle] cycle error:
// ./in.cue:11:6
// ./in.cue:12:6
}
b: (_|_){
// [cycle] cycle error:
// ./in.cue:11:6
// cycle error:
// ./in.cue:12:6
// cycle error:
// ./in.cue:13:6
}
c: (_|_){
// [cycle] cycle error:
// ./in.cue:11:6
// cycle error:
// ./in.cue:12:6
// cycle error:
// ./in.cue:13:6
}
}
permanentlyIncompleteOperands: (_|_){
// [eval]
a: (_|_){
// [eval] permanentlyIncompleteOperands.a: invalid operand string ('+' requires concrete value):
// ./in.cue:18:8
// ./in.cue:19:8
}
}
issue680: (_|_){
// [incomplete] issue680: non-concrete value >10 in operand to *:
// ./in.cue:23:12
}
}
-- out/compile --
--- in.cue
Expand All @@ -78,6 +87,7 @@ Result:
e1: (〈0;s〉 + 〈0;s〉)
e2: (>"bar" & 〈0;s〉)
e3: (>〈0;s〉 & "foo")
e3b: >〈0;s〉
e4: (>〈0;e1〉 & 〈0;s〉)
e5: (<〈0;e5〉 & 〈0;s〉)
E: {
Expand All @@ -89,4 +99,5 @@ Result:
a: ((string + ":") + string)
a: "golang/go:1.13.5"
}
issue680: ((>10 * 2) & 0)
}
12 changes: 9 additions & 3 deletions cue/testdata/export/009.txtar
Expand Up @@ -81,15 +81,21 @@ f: [1, 2, ...]
3: (int){ int }
4: (int){ int }
}
b: (list){
b: (_|_){
// [incomplete] b: non-concrete value <=5 in operand to *:
// ./in.cue:4:5
0: (int){ 1 }
1: (int){ 2 }
}
c: (list){
c: (_|_){
// [incomplete] c: non-concrete value >=3 & <=5 in operand to *:
// ./in.cue:6:5
0: (int){ 1 }
1: (int){ 2 }
}
d: (list){
d: (_|_){
// [incomplete] d: non-concrete value >=2 in operand to *:
// ./in.cue:8:5
0: (int){ 1 }
1: (int){ 2 }
}
Expand Down
12 changes: 9 additions & 3 deletions cue/testdata/export/010.txtar
Expand Up @@ -82,15 +82,21 @@ f: [1, 2, ...]
3: (int){ int }
4: (int){ int }
}
b: (list){
b: (_|_){
// [incomplete] b: non-concrete value <=5 in operand to *:
// ./in.cue:4:5
0: (int){ 1 }
1: (int){ 2 }
}
c: (list){
c: (_|_){
// [incomplete] c: non-concrete value >=3 & <=5 in operand to *:
// ./in.cue:6:5
0: (int){ 1 }
1: (int){ 2 }
}
d: (list){
d: (_|_){
// [incomplete] d: non-concrete value >=2 in operand to *:
// ./in.cue:8:5
0: (int){ 1 }
1: (int){ 2 }
}
Expand Down

0 comments on commit c091274

Please sign in to comment.