pkg/encoding: yaml.Validate doesn't handle disjunctions
What version of CUE are you using (cue version)?
$ cue version
cue version v0.7.0
go version go1.21.5
-buildmode exe
-compiler gc
-trimpath true
CGO_ENABLED 0
GOARCH amd64
GOOS linux
GOAMD64 v1
Does this issue reproduce with the latest stable release?
Yes, 0.7.0.
What did you do?
As per https://cuelang.slack.com/archives/C012UU8B72M/p1703146006424709:
exec cue export regularFields.cue
exec cue export requiredFields.cue
exec cue export closedStructs.cue
-- regularFields.cue --
package p
import "encoding/yaml"
#OneOf: {a: string} | {b: string}
example: yaml.Validate(#OneOf)
example: "a: foo"
-- requiredFields.cue --
package p
import "encoding/yaml"
#OneOf: {a!: string} | {b!: string}
example: yaml.Validate(#OneOf)
example: "a: foo"
-- closedStructs.cue --
package p
import "encoding/yaml"
#a: a: string
#b: b: string
#OneOf: #a | #b
example: yaml.Validate(#OneOf)
example: "a: foo"
None of the 3 attempts in the repro validates the inline YAML.
What did you expect to see?
A passing test, or at least /one/ of the attempts succeeding (i.e. fewer than 3 failures in the testscript --continue output).
What did you see instead?
$ testscript --continue yamlValidate.txtar
> exec cue export regularFields.cue
[stderr]
example: unresolved disjunction {a:string} | {b:string} (type struct):
./regularFields.cue:7:10
[exit status 1]
FAIL: /tmp/testscript3854620968/yamlValidate.txtar/script.txtar:1: unexpected command failure
> exec cue export requiredFields.cue
[stderr]
example: unresolved disjunction {a!:string} | {b!:string} (type struct):
./requiredFields.cue:7:10
[exit status 1]
FAIL: /tmp/testscript3854620968/yamlValidate.txtar/script.txtar:2: unexpected command failure
> exec cue export closedStructs.cue
[stderr]
example: unresolved disjunction {a:string} | {b:string} (type struct):
./closedStructs.cue:9:10
[exit status 1]
FAIL: /tmp/testscript3854620968/yamlValidate.txtar/script.txtar:3: unexpected command failure
error running yamlValidate.txtar in /tmp/testscript3854620968/yamlValidate.txtar
Verified that this is still a bug today, with and without the new evaluator experiment.
Noting per a conversation offline that this this particular example (of oneofs) is intrinsically linked to https://github.com/cue-lang/cue/issues/3165.
As of 9461bd296caec1abb7da62adfa436b469d4a86f2, the original testscript passes; the issue was resolved by https://review.gerrithub.io/c/cue-lang/cue/+/1194425.
That commit did not mark this issue as resolved because a closedness bug remained; however, that's unrelated to this issue, and it's already tracked in a TODO in the added tests in that commit.