cue: evaluator: incorrect behaviour when choosing defaults
What version of CUE are you using (cue version)?
$ cue version
cue version v0.0.0-20240712164527-719893f23850
go version go1.22.3
-buildmode exe
-compiler gc
DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
CGO_ENABLED 1
GOARCH arm64
GOOS linux
vcs git
vcs.revision 719893f23850172d224720e6d1257586179ac895
vcs.time 2024-07-12T16:45:27Z
vcs.modified false
cue.lang.version v0.10.0
Does this issue reproduce with the latest release?
Yes
What did you do?
! exec cue export x.cue
stderr 'b: 2 errors in empty disjunction'
stderr 'b: conflicting values 4 and 1'
stderr 'b: conflicting values 5 and 1'
-- x.cue --
a: *5 | int
if a == 5 {
b: 1
}
b: a | *4
What did you expect to see?
A passing test (for some variation perhaps of the error messages).
What did you see instead?
> ! exec cue export x.cue
[stdout]
{
"a": 5,
"b": 1
}
FAIL: /tmp/testscript4268956037/repro.txtar/script.txtar:1: unexpected command success
The output of b: 1 cannot be correct given that a: 5, and b is constrained such that b: a | *4.
To confirm: the exact same behaviour is seen with CUE_EXPERIMENT=evalv3, i.e. the bug exists in both old and new evaluator implementations.
Another observation: there is nowhere in the spec where we can refer to try and reason about what the behaviour should be here.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (16 by maintainers)
Yep, after much discussion and thought, I’m happy I’m in a less confused state wrt definitions etc.
… but clearly, if
ais 5, thenbmust be1(because of theif) and hence the above is not a valid result.FWIW my understanding is that this is (or should be) the case. In support of this, consider:
If
bjust made a deep copy ofa, then I think that it would end up as 5, because it wouldn’t be influenced by the eventual value ofa. But it ends up as 1, which seems right to me.In general if I see a reference, ISTM that it should always refer to the final value of the thing referred to. Anything else seems like it’s going to be less intuitive and useful.
Thus I believe that the original example should be an error of some kind (whether conflict or cycle I’m not quite sure).