From dd8ef3d37fbcc4569ac785bbbeba9f036f644d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 27 May 2026 10:46:01 +0100 Subject: [PATCH] cue/testdata: add test for issue #4091 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bug is resolved as of master; add a regression test. Closes #4091. Signed-off-by: Daniel Martí Change-Id: I1dbe8f1a7d8a234397d1198db3a5d8132385417d Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1237927 Reviewed-by: Marcel van Lohuizen TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine --- cue/testdata/comprehensions/issue4091.txtar | 36 ++++++++++ .../sync/comprehensions/issue4091.txtar | 71 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 cue/testdata/comprehensions/issue4091.txtar create mode 100644 internal/core/compile/testdata/sync/comprehensions/issue4091.txtar diff --git a/cue/testdata/comprehensions/issue4091.txtar b/cue/testdata/comprehensions/issue4091.txtar new file mode 100644 index 000000000..05125f15d --- /dev/null +++ b/cue/testdata/comprehensions/issue4091.txtar @@ -0,0 +1,36 @@ +# evalv3 incorrectly reported a "cyclic reference to field" error when a +# comprehension-based field (_volumes) was conditionally exposed (volumes) +# and then referenced through a generator pattern that re-binds the struct +# via {_input: _obj}. +# https://cuelang.org/issue/4091 +-- in.cue -- +output: (_Generator & {_input: _obj})._output @test(eq, { + genID: "id1" + _id: "id1" + volumeMounts: [{name: "mount1"}] + _volumes: {mount1: {name: "mount1"}} + volumes: {mount1: {name: "mount1"}} +}) + +_obj: spec: { + _id: "id1" + volumeMounts: [{name: "mount1"}] + _volumes: { + for _, vm in spec.volumeMounts { + (vm.name): name: vm.name + } + } + if len(_volumes) > 0 { + volumes: _volumes + } +} +_Generator: { + _input: {...} + _output: _input.spec + if _input.spec._id != _|_ { + _output: genID: (_input.spec._id) + } +} +-- out/errors.txt -- +[incomplete] _Generator._output: undefined field: spec: + ./in.cue:23:18 diff --git a/internal/core/compile/testdata/sync/comprehensions/issue4091.txtar b/internal/core/compile/testdata/sync/comprehensions/issue4091.txtar new file mode 100644 index 000000000..59b02835b --- /dev/null +++ b/internal/core/compile/testdata/sync/comprehensions/issue4091.txtar @@ -0,0 +1,71 @@ +# evalv3 incorrectly reported a "cyclic reference to field" error when a +# comprehension-based field (_volumes) was conditionally exposed (volumes) +# and then referenced through a generator pattern that re-binds the struct +# via {_input: _obj}. +# https://cuelang.org/issue/4091 +-- in.cue -- +output: (_Generator & {_input: _obj})._output @test(eq, { + genID: "id1" + _id: "id1" + volumeMounts: [{name: "mount1"}] + _volumes: {mount1: {name: "mount1"}} + volumes: {mount1: {name: "mount1"}} +}) + +_obj: spec: { + _id: "id1" + volumeMounts: [{name: "mount1"}] + _volumes: { + for _, vm in spec.volumeMounts { + (vm.name): name: vm.name + } + } + if len(_volumes) > 0 { + volumes: _volumes + } +} +_Generator: { + _input: {...} + _output: _input.spec + if _input.spec._id != _|_ { + _output: genID: (_input.spec._id) + } +} +-- out/compile -- +--- in.cue +{ + output: (〈0;_Generator〉 & { + _input: 〈1;_obj〉 + })._output + _obj: { + spec: { + _id: "id1" + volumeMounts: [ + { + name: "mount1" + }, + ] + _volumes: { + for _, vm in 〈2;spec〉.volumeMounts { + 〈1;vm〉.name: { + name: 〈2;vm〉.name + } + } + } + if (len(〈0;_volumes〉) > 0) { + volumes: 〈1;_volumes〉 + } + } + } + _Generator: { + _input: { + ... + } + _output: 〈0;_input〉.spec + if (〈0;_input〉.spec._id != _|_(explicit error (_|_ literal) in source)) { + _output: { + genID: 〈2;_input〉.spec._id + } + } + } +} -- 2.51.2