cue icon indicating copy to clipboard operation
cue copied to clipboard

disjunct which is just a comprehension does not behave as expected

Open august-feng opened this issue 1 year ago • 1 comments
trafficstars

What version of CUE are you using (cue version)?

$ cue version
cue version v0.6.0

go version go1.21.0
      -buildmode exe
       -compiler gc
  DefaultGODEBUG panicnil=1
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin

Does this issue reproduce with the latest stable release?

Yes.

What did you do?

cue export configuration.cue

-- configuration.cue --
#schema: [thing=string]: {
	says: "helloworld" | {
		if thing == "foobaz" {
			"bonjourmonde"
		}
	}
}

#schema & {
	"foobar": says: "helloworld"
	"foobaz": says: "bonjourmonde"
	"qux": says:    "holamundo"
}

What did you expect to see?

I expected to see some error messages about how the qux.says field cannot be holamundo:

qux.says: conflicting values "helloworld" and "holamundo":
    ./configuration.cue:1:26
    ./configuration.cue:2:8
    ./configuration.cue:5:1
    ./configuration.cue:8:18

What did you see instead?

{
    "foobar": {
        "says": "helloworld"
    },
    "foobaz": {
        "says": "bonjourmonde"
    },
    "qux": {
        "says": "holamundo"
    }
}

august-feng avatar Nov 28 '23 14:11 august-feng

Still seems to happen as of v0.13.0 on evalv3:

# evalv2
env CUE_EXPERIMENT=evalv3=0
! exec cue export in.cue

# evalv3
env CUE_EXPERIMENT=evalv3=1
! exec cue export in.cue

-- in.cue --
[Name=string]: "letter A" | {
	if Name == "B" {
		"letter B"
	}
}

A: "letter A"
B: "letter B"
Z: "should fail"
# evalv2 (0.007s)
> env CUE_EXPERIMENT=evalv3=0
> ! exec cue export in.cue
[stdout]
{
    "A": "letter A",
    "B": "letter B",
    "Z": "should fail"
}
FAIL: repro-evalv3.txtar:3: unexpected command success
# evalv3 (0.006s)
> env CUE_EXPERIMENT=evalv3=1
> ! exec cue export in.cue
[stdout]
{
    "A": "letter A",
    "B": "letter B",
    "Z": "should fail"
}
FAIL: repro-evalv3.txtar:7: unexpected command success

mvdan avatar May 30 '25 17:05 mvdan