Skip to content

eval: disjunction errors when repeating a sub-schema #3855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mvdan opened this issue Mar 27, 2025 · 4 comments
Open

eval: disjunction errors when repeating a sub-schema #3855

mvdan opened this issue Mar 27, 2025 · 4 comments

Comments

@mvdan
Copy link
Member

mvdan commented Mar 27, 2025

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

$ cue version
$ cue version
cue version v0.13.0-alpha.2.0.20250327101324-32d040003e8a

go version devel go1.25-1763ee199d 2025-03-26 17:58:32 -0700
      -buildmode exe
       -compiler gc
  DefaultGODEBUG decoratemappings=0,gotestjsonbuildtext=1,multipathtcp=0,randseednop=0,rsa1024min=0,tlsmlkem=0,x509rsacrt=0,x509usepolicies=0
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v3
             vcs git
    vcs.revision 32d040003e8a43b96d667d1ec2a2a02957853577
        vcs.time 2025-03-27T10:13:24Z
    vcs.modified false
cue.lang.version v0.13.0

Does this issue reproduce with the latest stable release?

Yes; tested on v0.12.0 with evalv2 too.

What did you do?

# evalv2
env CUE_EXPERIMENT=evalv3=0
exec cue export

# evalv3
env CUE_EXPERIMENT=evalv3=1
exec cue export

-- input.cue --
package p

#schema: {
	a: "a1" | "a2"

	if a == "a1" { b: "b" }
	if a == "a2" { c: "c" }

	x: "x1" | "x2"
}

out: #schema & {
	a: "a2"
	// Remove `#schema.x &` and the config works.
	x: #schema.x & "x1"
}

What did you expect to see?

The testscript should pass, at least with evalv3; as far as I can tell, the configuration is valid. The repeating of the schema for the field out.x should not cause any issues.

What did you see instead?

# evalv2 (0.011s)
> env CUE_EXPERIMENT=evalv3=0
> exec cue export
[stderr]
out.x: 3 errors in empty disjunction:
out.x: conflicting values "x2" and "x1":
    ./input.cue:9:12
    ./input.cue:12:6
    ./input.cue:15:17
#schema: unresolved disjunction "a1" | "a2" (type string):
    ./input.cue:6:5
#schema: unresolved disjunction "a1" | "a2" (type string):
    ./input.cue:7:5
[exit status 1]
FAIL: repro-evalv3.txtar:3: unexpected command failure
# evalv3 (0.029s)
> env CUE_EXPERIMENT=evalv3=1
> exec cue export
[stderr]
out.x: 3 errors in empty disjunction:
out.x: conflicting values "x2" and "x1":
    ./input.cue:9:12
    ./input.cue:15:17
#schema: unresolved disjunction "a1" | "a2" (type string):
    ./input.cue:6:5
#schema: unresolved disjunction "a1" | "a2" (type string):
    ./input.cue:7:5
[exit status 1]
FAIL: repro-evalv3.txtar:7: unexpected command failure
@mvdan
Copy link
Member Author

mvdan commented Mar 27, 2025

Not a regression from evalv2, hence no evalv3 label nor prioritizing as a regression.

@mvdan
Copy link
Member Author

mvdan commented Mar 27, 2025

Also rather puzzling that two of the errors have the path #schema, which definitely seems wrong.

@myitcv myitcv changed the title disjunction errors when repeating a sub-schema eval: disjunction errors when repeating a sub-schema Mar 27, 2025
@mpvl
Copy link
Member

mpvl commented Mar 27, 2025

The way CUE works now, this is not a bug: the comprehensions of #schema are defined at the top level, and CUE requires them to be successfully evaluated either way before a lookup may be performed on that schema.

I know it is theoretically not necessary in this case, but that is how it is defined as of now.

We may loosen this behavior in the future.

@myitcv
Copy link
Member

myitcv commented Mar 27, 2025

The way CUE works now, this is not a bug

There are two things being pointed out here:

  1. out.x: conflicting values "x2" and "x1":
  2. the #schema-related errors

Which were you referring to?

Because I can't think that 1 is expected behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants