Skip to content

Commit

Permalink
internal/core/eval: fix Evaluator sync bug
Browse files Browse the repository at this point in the history
Environment was not set up for correct usage in two cases.

For Let expressions, it just happend to always end up at the
correct node in the tests before.

For relNode, this was only exposed for discontinuous
evaluations, which are actually quite rare.

Also, added a bit more aggressive error reporting for
list comprehensions.

Change-Id: Iba14b539a9f84a2960c3170afe68acbeb93ae1ec
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6681
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
  • Loading branch information
mpvl committed Jul 23, 2020
1 parent 765f87e commit 07e40c6
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 9 deletions.
45 changes: 45 additions & 0 deletions cue/testdata/comprehensions/lists.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- in.cue --

a: [{a: 1}, {b: 2 & 3}]

b: [ for x in a { x } ]
-- out/eval --
Errors:
a.1.b: incompatible values 3 and 2

Result:
(_|_){
// [eval]
a: (_|_){
// [eval]
0: (struct){
a: (int){ 1 }
}
1: (_|_){
// [eval]
b: (_|_){
// [eval] a.1.b: incompatible values 3 and 2
}
}
}
b: (_|_){
// [eval] a.1.b: incompatible values 3 and 2
}
}
-- out/compile --
--- in.cue
{
a: [
{
a: 1
},
{
b: (2 & 3)
},
]
b: [
for _, x in 〈0;a〉 {
〈1;x〉
},
]
}
11 changes: 9 additions & 2 deletions cue/testdata/cycle/023_reentrance.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ fib12: 144
}).out
}
-- out/eval --
Errors:
structural cycle:
./in.cue:8:9

Result:
(_|_){
// [structural cycle]
fibRec: (struct){
Expand All @@ -95,9 +100,11 @@ fib12: 144
}
fib2: (int){ 1 }
fib7: (_|_){
// [structural cycle]
// [structural cycle] structural cycle:
// ./in.cue:8:9
}
fib12: (_|_){
// [structural cycle]
// [structural cycle] structural cycle:
// ./in.cue:8:9
}
}
12 changes: 9 additions & 3 deletions cue/testdata/cycle/structural.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ e3.b.c: conflicting types list and struct
e3.b.c: structural cycle
z1.z.f.h.h: structural cycle
z1.z.g.h: structural cycle
b4.x.y.0: structural cycle:
./in.cue:41:8
d2.a.b.c.d.t: structural cycle:
./in.cue:79:8
d2.r: structural cycle:
./in.cue:79:8

Expand Down Expand Up @@ -321,7 +325,8 @@ Result:
b4: (_|_){
// [structural cycle]
b: (_|_){
// [structural cycle]
// [structural cycle] b4.x.y.0: structural cycle:
// ./in.cue:41:8
0: (int){ 1 }
}
x: (_|_){
Expand Down Expand Up @@ -448,13 +453,14 @@ Result:
}
}
x: (_|_){
// [structural cycle]
// [structural cycle] d1.a.b.c.d.t: structural cycle
}
}
d2: (_|_){
// [structural cycle]
x: (_|_){
// [structural cycle]
// [structural cycle] d2.a.b.c.d.t: structural cycle:
// ./in.cue:79:8
}
r: (_|_){
// [structural cycle] d2.r: structural cycle:
Expand Down
76 changes: 76 additions & 0 deletions cue/testdata/eval/discontinuous.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
This test tests a case where a child node needs to be evaluated
before evaluating a parent has completed.

-- in.cue --
a: [ for c in foo.bar.baz {
c
}]

a: [{name: "http"}]

foo: {
x.D

bar: baz: [{port: 8080}]
}

x: {
D: bar: DSpec
DSpec: {}
}
-- out/compile --
--- in.cue
{
a: [
for _, c in 〈0;foo〉.bar.baz {
〈1;c〉
},
]
a: [
{
name: "http"
},
]
foo: {
〈1;x〉.D
bar: {
baz: [
{
port: 8080
},
]
}
}
x: {
D: {
bar: 〈1;DSpec〉
}
DSpec: {}
}
}
-- out/eval --
(struct){
a: (#list){
0: (struct){
port: (int){ 8080 }
name: (string){ "http" }
}
}
foo: (struct){
bar: (struct){
baz: (#list){
0: (struct){
port: (int){ 8080 }
}
}
}
}
x: (struct){
D: (struct){
bar: (struct){
}
}
DSpec: (struct){
}
}
}

0 comments on commit 07e40c6

Please sign in to comment.