blob: 605639b06d2fc9802df367c060a2a1504acdf23f [file] [log] [blame]
It turns out the semantics of the spec is somewhat awkward,
though theoretically nicer. It seems like we do need to change
the definition somewhat to make it less awkward, or at least
come up with a good workaround before adopting the spec.
We have introduce a small hack to mimic the old behavior for scalar
values.
Note that the value of p below is now 2 (default), but should
be the non-concrete 2 | int.
Proof:
p: *((*1 | int) & 2) | int // substitution of both P conjuncts in p
p: *(*_|_ | 2) | int // U1: distribute conjuncts
p: *_|_ | 2 | int // M2: remove mark
p: 2 | int // value after removing default.
-- in.cue --
Q: *1 | int
q: *Q | int // 1 as expected
P: *1 | int
P: 2
p: *P | int // now 2, but should be (2 | int), according to the spec:
// Here the inner default may not be used as it is masked by the outer default.
r: (*3 | (*1 | 2)) & (1 | 2)
// Here the inner default is used, as there are no defaults marked in the
// outer disjunction.
s: (3 | (*1 | 2)) & (1 | 2)
s1: #Size & { min: 5 }
#Size : {
max: >min | *min
res: uint | * 0
min: >res | *(1 + res)
}
staged: {
c: ("a" | "b") & (*(*"a" | string) | string)
d: (*(*"a" | string) | string) & ("a" | "b")
}
issue763a: {
#A: {
v: "a" | "b" | "c" // change to string to fix
}
h: [string]: #A
h: [=~"^b"]: #A & {
v: *h.a.v | string
}
h: a: {
v: *"a" | string
}
h: baa: _
h: boo: _
}
-- out/eval --
(struct){
Q: (int){ |(*(int){ 1 }, (int){ int }) }
q: (int){ |(*(int){ 1 }, (int){ int }) }
P: (int){ 2 }
p: (int){ |(*(int){ 2 }, (int){ int }) }
r: (int){ |((int){ 1 }, (int){ 2 }) }
s: (int){ |(*(int){ 1 }, (int){ 2 }) }
s1: (#struct){
max: (number){ |(*(int){ 5 }, (number){ >5 }) }
res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
min: (int){ 5 }
}
#Size: (#struct){
max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) }
res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) }
min: (number){ |(*(int){ 1 }, (number){ >0 }) }
}
staged: (struct){
c: (string){ |(*(string){ "a" }, (string){ "b" }) }
d: (string){ |(*(string){ "a" }, (string){ "b" }) }
}
issue763a: (struct){
#A: (#struct){
v: (string){ |((string){ "a" }, (string){ "b" }, (string){ "c" }) }
}
h: (struct){
a: (#struct){
v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) }
}
baa: (#struct){
v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) }
}
boo: (#struct){
v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) }
}
}
}
}
-- out/compile --
--- in.cue
{
Q: (*1|int)
q: (*〈0;Q〉|int)
P: (*1|int)
P: 2
p: (*〈0;P〉|int)
r: ((*3|(*1|2)) & (1|2))
s: ((3|(*1|2)) & (1|2))
s1: (〈0;#Size & {
min: 5
})
#Size: {
max: (>〈0;min〉|*〈0;min〉)
res: (&(int, >=0)|*0)
min: (>〈0;res〉|*(1 + 0;res〉))
}
staged: {
c: (("a"|"b") & (*(*"a"|string)|string))
d: ((*(*"a"|string)|string) & ("a"|"b"))
}
issue763a: {
#A: {
v: ("a"|"b"|"c")
}
h: {
[string]: 1;#A
}
h: {
[=~"^b"]: (〈1;#A & {
v: (*〈2;h〉.a.v|string)
})
}
h: {
a: {
v: (*"a"|string)
}
}
h: {
baa: _
}
h: {
boo: _
}
}
}