From ff93ba0ae8d887f0a874a523a7855d0d8fe40161 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Wed, 24 Nov 2021 15:07:22 +0100 Subject: [PATCH] internal/core/adt: don't cache incomplete errors for let These may be resolved later. Issue #1116 Signed-off-by: Marcel van Lohuizen Change-Id: I46b8dda41193b41f5b6b0fd341164a2568697bfc --- cue/testdata/references/let.txtar | 44 +++++++++++++++++++++++++++++++ internal/core/adt/composite.go | 4 ++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/cue/testdata/references/let.txtar b/cue/testdata/references/let.txtar index 550855db7e7..7a0ad177c59 100644 --- a/cue/testdata/references/let.txtar +++ b/cue/testdata/references/let.txtar @@ -63,6 +63,18 @@ incompleteLet: { } } } +issue1116: { + a: { + #a: ["a", "b"] + let List = #a + List[len(List)-1] + } + b: { + let List = #a + List[len(List)-1] + #a: ["a", "b"] + } +} -- out/compile -- --- in.cue @@ -183,6 +195,22 @@ incompleteLet: { if (〈import;list〉.max < 0) {} } } + issue1116: { + a: { + #a: [ + "a", + "b", + ] + 〈0;let List〉[(len(〈0;let List〉) - 1)] + } + b: { + 〈0;let List〉[(len(〈0;let List〉) - 1)] + #a: [ + "a", + "b", + ] + } + } } -- out/eval -- (struct){ @@ -282,4 +310,20 @@ incompleteLet: { // ./in.cue:61:17 } } + issue1116: (struct){ + a: (string){ + "b" + #a: (#list){ + 0: (string){ "a" } + 1: (string){ "b" } + } + } + b: (string){ + "b" + #a: (#list){ + 0: (string){ "a" } + 1: (string){ "b" } + } + } + } } diff --git a/internal/core/adt/composite.go b/internal/core/adt/composite.go index 47204724474..d145d453aa2 100644 --- a/internal/core/adt/composite.go +++ b/internal/core/adt/composite.go @@ -142,7 +142,9 @@ func (e *Environment) evalCached(c *OpContext, x Expr) Value { c.e, c.src = e, x.Source() v = c.evalState(x, Partial) // TODO: should this be Finalized? c.e, c.src = env, src - e.cache[x] = v + if b, ok := v.(*Bottom); !ok || !b.IsIncomplete() { + e.cache[x] = v + } } return v }