Skip to content

Commit 9982526

Browse files
committed
internal/core/adt: don't cache incomplete errors for let
These may be resolved later. Issue #1116 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Change-Id: I46b8dda41193b41f5b6b0fd341164a2568697bfc Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/528052 Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
1 parent 4f3988f commit 9982526

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

cue/testdata/references/let.txtar

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ incompleteLet: {
6363
}
6464
}
6565
}
66+
issue1116: {
67+
a: {
68+
#a: ["a", "b"]
69+
let List = #a
70+
List[len(List)-1]
71+
}
72+
b: {
73+
let List = #a
74+
List[len(List)-1]
75+
#a: ["a", "b"]
76+
}
77+
}
6678

6779
-- out/compile --
6880
--- in.cue
@@ -183,6 +195,22 @@ incompleteLet: {
183195
if (〈import;list〉.max < 0) {}
184196
}
185197
}
198+
issue1116: {
199+
a: {
200+
#a: [
201+
"a",
202+
"b",
203+
]
204+
〈0;let List〉[(len(〈0;let List〉) - 1)]
205+
}
206+
b: {
207+
〈0;let List〉[(len(〈0;let List〉) - 1)]
208+
#a: [
209+
"a",
210+
"b",
211+
]
212+
}
213+
}
186214
}
187215
-- out/eval --
188216
(struct){
@@ -282,4 +310,20 @@ incompleteLet: {
282310
// ./in.cue:61:17
283311
}
284312
}
313+
issue1116: (struct){
314+
a: (string){
315+
"b"
316+
#a: (#list){
317+
0: (string){ "a" }
318+
1: (string){ "b" }
319+
}
320+
}
321+
b: (string){
322+
"b"
323+
#a: (#list){
324+
0: (string){ "a" }
325+
1: (string){ "b" }
326+
}
327+
}
328+
}
285329
}

internal/core/adt/composite.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ func (e *Environment) evalCached(c *OpContext, x Expr) Value {
142142
c.e, c.src = e, x.Source()
143143
v = c.evalState(x, Partial) // TODO: should this be Finalized?
144144
c.e, c.src = env, src
145-
e.cache[x] = v
145+
if b, ok := v.(*Bottom); !ok || !b.IsIncomplete() {
146+
e.cache[x] = v
147+
}
146148
}
147149
return v
148150
}

0 commit comments

Comments
 (0)