cue
cue copied to clipboard
evaluator: comprehension cycle reported where previously this was allowed
What version of CUE are you using (cue version
)?
$ cue version cue version v0.0.0-20220915134846-df148ee6b613 -compiler gc CGO_ENABLED 1 GOARCH arm64 GOOS linux vcs git vcs.revision df148ee6b6133e0466f7964eec027f2e0349cdbe vcs.time 2022-09-15T13:48:46Z vcs.modified true
Does this issue reproduce with the latest release?
Yes
What did you do?
exec cue export x.cue
cmp stdout stdout.golden
-- x.cue --
package preguide
#Guide: {
// Scenarios defines the set of scenarios this guide should cover.
Scenarios: [name=string]: #Scenario & {
Name: name
}
// Terminals declares the required terminals for this guide.
Terminals: [name=string]: #Terminal & {
Name: name
}
// This for loop templates to ensure that terminal declares an
// image for every scenario.
for scenario, _ in Scenarios for terminal, _ in Terminals {
Terminals: "\(terminal)": Scenarios: "\(scenario)": #TerminalScenario
}
}
#Terminal: {
Name: string
Scenarios: [string]: #TerminalScenario
}
#TerminalScenario: {
Image: string
}
#Scenario: {
Name: string
Description: string
}
g1: #Guide & {
Terminals: term1: #Terminal & {
Scenarios: go115: Image: "this_will_never_be_used"
}
Scenarios: go115: {
Description: "Go 1.15"
}
}
-- stdout.golden --
{
"g1": {
"Scenarios": {
"go115": {
"Name": "go115",
"Description": "Go 1.15"
}
},
"Terminals": {
"term1": {
"Name": "term1",
"Scenarios": {
"go115": {
"Image": "this_will_never_be_used"
}
}
}
}
}
}
What did you expect to see?
Passing test. This passes with v0.4.1.
What did you see instead?
With tip (df148ee6):
> exec cue export x.cue
[stderr]
cycle error:
./x.cue:16:50
[exit status 1]
FAIL: /tmp/testscript1377975653/repro.txtar/script.txtar:1: unexpected command failure
What's interesting is that this got broken in be2ee9b62d2d9326fe025bed40215d7b5104a662. However the output against that commit is different to tip:
> exec cue export x.cue
[stderr]
g1: cannot add field Terminals: was already used:
./x.cue:17:3
[exit status 1]
FAIL: /tmp/testscript2841319868/repro.txtar/script.txtar:1: unexpected command failure
Moving the Scenarios
comprehension inside the Terminals
declaration fixes this:
exec cue export x.cue
cmp stdout stdout.golden
-- x.cue --
package preguide
#Guide: {
// Scenarios defines the set of scenarios this guide should cover.
Scenarios: [name=string]: #Scenario & {
Name: name
}
// Terminals declares the required terminals for this guide.
Terminals: [name=string]: #Terminal & {
Name: name
for scenario, _ in Scenarios {
Scenarios: "\(scenario)": #TerminalScenario
}
}
}
#Terminal: {
Name: string
Scenarios: [string]: #TerminalScenario
}
#TerminalScenario: {
Image: string
}
#Scenario: {
Name: string
Description: string
}
g1: #Guide & {
Terminals: term1: #Terminal & {
Scenarios: go115: Image: "this_will_never_be_used"
}
Scenarios: go115: {
Description: "Go 1.15"
}
}
-- stdout.golden --
{
"g1": {
"Scenarios": {
"go115": {
"Name": "go115",
"Description": "Go 1.15"
}
},
"Terminals": {
"term1": {
"Name": "term1",
"Scenarios": {
"go115": {
"Image": "this_will_never_be_used"
}
}
}
}
}
}
Passes with tip (https://github.com/cue-lang/cue/commit/df148ee6b6133e0466f7964eec027f2e0349cdbe) as expected.
I have a similar issue with the following snipped and cue version 0.4.3 darwin/arm64
but it also happens with other 0.4.x versions
panels: [ for i in panels {
{
id: i
}
}]
@fionera: a fix for this is also planned for v0.5, although you probably meant:
panels: [ for i, _ in panels {
{
id: i
}
}]