Skip to content

Commit 55602d9

Browse files
committed
internal/core/eval: fix closedness issue for lists
closedness updates were previously incorrectly skipped. Note that list acceptance checks are checked elsewhere and should be skipped. Fixes #595 Change-Id: I962bef093fa8623724e9c45105aedd184ed20a8b Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7785 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent ec6f95d commit 55602d9

File tree

4 files changed

+73
-6
lines changed

4 files changed

+73
-6
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- in.cue --
2+
issue595: {
3+
// NOTE: this should eval with an EVAL error, not
4+
// an incomplete error. See Issue #595.
5+
#cfgs: [{
6+
name: "foo"
7+
}]
8+
for cfg in #cfgs {
9+
files: cfg.nam
10+
}
11+
}
12+
-- out/eval --
13+
Errors:
14+
issue595.files: undefined field nam:
15+
./in.cue:8:20
16+
17+
Result:
18+
(_|_){
19+
// [eval]
20+
issue595: (_|_){
21+
// [eval]
22+
#cfgs: (#list){
23+
0: (#struct){
24+
name: (string){ "foo" }
25+
}
26+
}
27+
files: (_|_){
28+
// [eval] issue595.files: undefined field nam:
29+
// ./in.cue:8:20
30+
}
31+
}
32+
}
33+
-- out/compile --
34+
--- in.cue
35+
{
36+
issue595: {
37+
#cfgs: [
38+
{
39+
name: "foo"
40+
},
41+
]
42+
for _, cfg in 〈0;#cfgs〉 {
43+
files: 〈1;cfg〉.nam
44+
}
45+
}
46+
}

internal/core/eval/eval.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,6 @@ func (n *nodeContext) updateClosedInfo() {
639639
// later. Logically we're done.
640640
}
641641

642-
if n.node.IsList() {
643-
return
644-
}
645-
646642
a, _ := n.node.Closed.(*acceptor)
647643
if a == nil {
648644
if !n.node.IsList() && !n.needClose {
@@ -660,7 +656,9 @@ func (n *nodeContext) updateClosedInfo() {
660656
// for Value.Unify (API).
661657
ctx := n.ctx
662658

663-
if accept := n.nodeShared.accept; accept != nil {
659+
// TODO: record the list length for the acceptor, possibly. But the
660+
// length matching should already have been done.
661+
if accept := n.nodeShared.accept; accept != nil && !n.node.IsList() {
664662
for _, a := range n.node.Arcs {
665663
if !accept.Accept(n.ctx, a.Label) {
666664
label := a.Label.SelectorString(ctx)

tools/trim/testdata/listaccept.txtar

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- in.cue --
2+
deployment: [ID=_]: {
3+
containers: [{}]
4+
}
5+
6+
deployment: bartender: {
7+
containers: [{
8+
image: "gcr.io/myproj/bartender:v0.1.34"
9+
}]
10+
}
11+
-- out/trim --
12+
== in.cue
13+
deployment: [ID=_]: {
14+
containers: [{}]
15+
}
16+
17+
deployment: bartender: {
18+
containers: [{
19+
image: "gcr.io/myproj/bartender:v0.1.34"
20+
}]
21+
}

tools/trim/trim_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ func TestX(t *testing.T) {
326326

327327
files := instances[0].Files
328328

329-
err := Files(files, inst, &Config{Trace: false})
329+
err := Files(files, inst, &Config{
330+
Trace: true,
331+
})
330332
if err != nil {
331333
t.Fatal(err)
332334
}

0 commit comments

Comments
 (0)