Open rogpeppe opened 1 year ago
As usually is the case in CUE evaluation, the value of b
in both(1|2)
is recomputed. So x.b & y.b
failing does, in general, not imply that x & y
fails. For instance:
x: {
a: *1 | 2
b: a
}
y: {
a: 2
b: 2
}
z: x & y
Even though x.b & y.b
fails, x & y
is valid.
The current CUE was designed to adhere to a topological sort, falling back to a deterministic order if topological sort is not possible. So in that case, both1.b
and both2.b
should indeed have the same value. But this can be the case even if source1.b
and source2.b
are different.
Note to self to write up notes/conclusions from this conversation.
Linking to the issue which covers us defining order in the spec: https://github.com/cue-lang/cue/issues/474.
@mpvl
As usually is the case in CUE evaluation, the value of
b
inboth(1|2)
is recomputed
For my own understanding, is it that b
is recomputed, or rather that its evaluation is, in all cases, delayed, and therefore happens after all unifications have been considered?
To my mind, the issue is more clear cut than the comments above seem to make it out.
To my mind, one of the core properties of CUE is that it's commutative. That is, for any two subexpressions a
and b
, the result of a & b
should be the same as the result of b & a
. To my mind, that property is clearly violated here:
both1: source2 & source1
both2: source1 & source2
If &
is truly commutative, then the result of both1
and both2
will be the same irrespective of what's inside source1
and source2
.
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest stable release?
Yes
What did you do?
Export this code:
What did you expect to see?
both1
andboth2
should be in error becausesource1.b
andsource2.b
are different, so there's a conflict.Alternatively,
json.Marshal
should ignore source order andsource1
,source2
,both1
, andboth2
should be identical and contain the same fields in the same order.What did you see instead?