cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.16k stars 297 forks source link

evalv3: "conflicting values" error regression when a disjunction involves missing fields #3600

Open mvdan opened 1 week ago

mvdan commented 1 week ago
# With the old evaluator.
env CUE_EXPERIMENT=evalv3=0
exec cue vet -c=false

# With the new evaluator.
env CUE_EXPERIMENT=evalv3=1
exec cue vet -c=false

-- input.cue --
package p

#PatchOp: {
    op:    "replace"
    value: _
} | {
    op:   "remove"
} | {
    op:   "copy"
    from: string
}
#Patch: {
    input:  #PatchOp
    output: input
}

params: {}
patched: (#Patch & {
    input: {
        op:    "replace"
        value: "\(params.missing)"
    }
}).output

As of c29fd02c46f0c438148d1051489bf42122f59f19:

# With the old evaluator. (0.010s)
> env CUE_EXPERIMENT=evalv3=0
> exec cue vet -c=false
# With the new evaluator. (0.028s)
> env CUE_EXPERIMENT=evalv3=1
> exec cue vet -c=false
[stderr]
output.op: conflicting values "copy" and "replace":
    ./input.cue:9:8
    ./input.cue:20:10
output.op: conflicting values "remove" and "replace":
    ./input.cue:7:8
    ./input.cue:20:10

The config is incomplete, as params.missing is not a field that exists, but still - I think v2 was correct in not reporting the "conflicting values" errors which do not matter here.

mvdan commented 6 days ago

Slightly smaller testscript:

# With the old evaluator.
env CUE_EXPERIMENT=evalv3=0
exec cue vet -c=false

# With the new evaluator.
env CUE_EXPERIMENT=evalv3=1
exec cue vet -c=false

-- input.cue --
package p

#PatchOp: {
    op:    "replace"
    value: _
} | {
    op:   "remove"
} | {
    op:   "copy"
    from: string
}

params: {}
patched: #PatchOp & {
    op:    "replace"
    value: "\(params.missing)"
}