cue
cue copied to clipboard
internal/core: inconsistent default value resolution depending on ordering and marks
What version of CUE are you using (cue version)?
0.4.0
What did you do?
exec cue eval defaults.cue
-- defaults.cue --
a: [{
x: *(1|2) | (1|*2)
y: *(1|2) | (*1|2)
}, {
x: (1|*2) | *(1|2)
y: (*1|2) | *(1|2)
}, {
x: (1|2) | (1|*2)
y: (1|2) | (*1|2)
}]
b: [{
x: *1 | (1|*2)
y: *1 | (*1|2)
}, {
x: (1|*2) | *1
y: (*1|2) | *1
}, {
x: 1 | (1|*2)
y: 1 | (*1|2)
}]
c: [{
x: (*1|2) | (*1|2)
y: *(*1|2) | (*1|2)
z: (*1|2) | *(*1|2)
}]
What did you see?
a: [{
x: 1
y: 2
}, {
x: 1 | 2
y: 1 | 2
}, {
x: 2
y: 1
}]
b: [{
x: 1
y: 1 | 2
}, {
x: 1
y: 1
}, {
x: 2
y: 1
}]
c: [{
x: 1
y: 1 | 2
z: 1
}]
What did you expect to see?
Not exactly sure on the rules for how these defaults should be eliminated and what the results should be.
There are certain inconsistencies
a.0I would expect x and y to be the other, i.e. matcha.2a.0vsa.1I would expect the same answer for both, as the L/R top-level have switch sides- same for
b.0vsb.1 c.0I would expect all to be the same,1
There are clearly some bugs here.
Further investigation:
According to the spec, this is what it should be:
a: [{
x: 1|2 // rule M1 and M3
y: 1|2 // rule M1 and M3
}, {
x: 1|2 // rule M1 and M3
y: 1|2 // rule M1 and M3
}, {
x: 1|*2 // rule D1
y: *1|2 // rule D1
}]
b: [{
x: *1 | 2 // rule M1, M3, D1
y: *1 | 2 // rule M1, M3, D1
}, {
x: *1 | 2 // rule M1, M3, D1
y: *1 | 2 // rule M1, M3, D1
}, {
x: 1 | *2 // rule D1
y: *1 | 2 // rule D1
}]
c: [{
x: *1|2 // rule D2
y: *1|2
z: *1|2
}]
So the following are erroneous: a.0.x, a.0.y, b.0.y, c.0.y.
Bug was introduced with a spec change regarding defaults at 87d43b74397e1bdabe190e96e0c52561fe83d685.
The old semantics coincidentally yielded the same result in many of these cases, but the new implementation doesn't implement the new (much simpler) semantics correctly, evidentally.