cuelang.org/go@v0.10.1/cue/testdata/disjunctions/specdeviation.txtar (about) 1 It turns out the semantics of the spec is somewhat awkward, 2 though theoretically nicer. It seems like we do need to change 3 the definition somewhat to make it less awkward, or at least 4 come up with a good workaround before adopting the spec. 5 6 We have introduce a small hack to mimic the old behavior for scalar 7 values. 8 9 Note that the value of p below is now 2 (default), but should 10 be the non-concrete 2 | int. 11 12 Proof: 13 p: *((*1 | int) & 2) | int // substitution of both P conjuncts in p 14 p: *(*_|_ | 2) | int // U1: distribute conjuncts 15 p: *_|_ | 2 | int // M2: remove mark 16 p: 2 | int // value after removing default. 17 18 -- in.cue -- 19 Q: *1 | int 20 q: *Q | int // 1 as expected 21 22 P: *1 | int 23 P: 2 24 p: *P | int // now 2, but should be (2 | int), according to the spec: 25 26 // Here the inner default may not be used as it is masked by the outer default. 27 r: (*3 | (*1 | 2)) & (1 | 2) 28 29 // Here the inner default is used, as there are no defaults marked in the 30 // outer disjunction. 31 s: (3 | (*1 | 2)) & (1 | 2) 32 33 s1: #Size & {min: 5} 34 35 #Size: { 36 max: >min | *min 37 res: uint | *0 38 min: >res | *(1 + res) 39 } 40 41 staged: { 42 c: ("a" | "b") & (*(*"a" | string) | string) 43 d: (*(*"a" | string) | string) & ("a" | "b") 44 } 45 46 issue763a: { 47 #A: { 48 v: "a" | "b" | "c" // change to string to fix 49 } 50 51 h: [string]: #A 52 53 h: [=~"^b"]: #A & { 54 v: *h.a.v | string 55 } 56 57 h: a: { 58 v: *"a" | string 59 } 60 61 h: baa: _ 62 h: boo: _ 63 } 64 -- out/eval/stats -- 65 Leaks: 0 66 Freed: 171 67 Reused: 158 68 Allocs: 13 69 Retain: 2 70 71 Unifications: 28 72 Conjuncts: 217 73 Disjuncts: 172 74 -- out/evalalpha -- 75 (struct){ 76 Q: (int){ |(*(int){ 1 }, (int){ int }) } 77 q: (int){ |(*(int){ 1 }, (int){ int }) } 78 P: (int){ 2 } 79 p: (int){ |((int){ 2 }, (int){ int }) } 80 r: (int){ |((int){ 1 }, (int){ 2 }) } 81 s: (int){ |(*(int){ 1 }, (int){ 2 }) } 82 s1: (#struct){ 83 min: (int){ 5 } 84 max: (number){ |((number){ >5 }, (int){ 5 }) } 85 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 86 } 87 #Size: (#struct){ 88 max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) } 89 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 90 min: (number){ |(*(int){ 1 }, (number){ >0 }) } 91 } 92 staged: (struct){ 93 c: (string){ |(*(string){ "a" }, (string){ "b" }) } 94 d: (string){ |(*(string){ "a" }, (string){ "b" }) } 95 } 96 issue763a: (struct){ 97 #A: (#struct){ 98 v: (string){ |((string){ "a" }, (string){ "b" }, (string){ "c" }) } 99 } 100 h: (struct){ 101 a: (#struct){ 102 v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 103 } 104 baa: (#struct){ 105 v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 106 } 107 boo: (#struct){ 108 v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 109 } 110 } 111 } 112 } 113 -- diff/-out/evalalpha<==>+out/eval -- 114 diff old new 115 --- old 116 +++ new 117 @@ -2,13 +2,13 @@ 118 Q: (int){ |(*(int){ 1 }, (int){ int }) } 119 q: (int){ |(*(int){ 1 }, (int){ int }) } 120 P: (int){ 2 } 121 - p: (int){ |(*(int){ 2 }, (int){ int }) } 122 + p: (int){ |((int){ 2 }, (int){ int }) } 123 r: (int){ |((int){ 1 }, (int){ 2 }) } 124 s: (int){ |(*(int){ 1 }, (int){ 2 }) } 125 s1: (#struct){ 126 - max: (number){ |(*(int){ 5 }, (number){ >5 }) } 127 - res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 128 min: (int){ 5 } 129 + max: (number){ |((number){ >5 }, (int){ 5 }) } 130 + res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 131 } 132 #Size: (#struct){ 133 max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) } 134 -- diff/explanation -- 135 The changes in default behavior as are shown here are according to spec, as is 136 described at the top of the file. These changes may pose too much of a problem 137 for the transition to the new evaluator, though. 138 TODO: consider reintroducing bugs. 139 -- diff/todo/p3 -- 140 Reordering. 141 -- out/eval -- 142 (struct){ 143 Q: (int){ |(*(int){ 1 }, (int){ int }) } 144 q: (int){ |(*(int){ 1 }, (int){ int }) } 145 P: (int){ 2 } 146 p: (int){ |(*(int){ 2 }, (int){ int }) } 147 r: (int){ |((int){ 1 }, (int){ 2 }) } 148 s: (int){ |(*(int){ 1 }, (int){ 2 }) } 149 s1: (#struct){ 150 max: (number){ |(*(int){ 5 }, (number){ >5 }) } 151 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 152 min: (int){ 5 } 153 } 154 #Size: (#struct){ 155 max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) } 156 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 157 min: (number){ |(*(int){ 1 }, (number){ >0 }) } 158 } 159 staged: (struct){ 160 c: (string){ |(*(string){ "a" }, (string){ "b" }) } 161 d: (string){ |(*(string){ "a" }, (string){ "b" }) } 162 } 163 issue763a: (struct){ 164 #A: (#struct){ 165 v: (string){ |((string){ "a" }, (string){ "b" }, (string){ "c" }) } 166 } 167 h: (struct){ 168 a: (#struct){ 169 v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 170 } 171 baa: (#struct){ 172 v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 173 } 174 boo: (#struct){ 175 v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 176 } 177 } 178 } 179 } 180 -- out/compile -- 181 --- in.cue 182 { 183 Q: (*1|int) 184 q: (*〈0;Q〉|int) 185 P: (*1|int) 186 P: 2 187 p: (*〈0;P〉|int) 188 r: ((*3|(*1|2)) & (1|2)) 189 s: ((3|(*1|2)) & (1|2)) 190 s1: (〈0;#Size〉 & { 191 min: 5 192 }) 193 #Size: { 194 max: (>〈0;min〉|*〈0;min〉) 195 res: (&(int, >=0)|*0) 196 min: (>〈0;res〉|*(1 + 〈0;res〉)) 197 } 198 staged: { 199 c: (("a"|"b") & (*(*"a"|string)|string)) 200 d: ((*(*"a"|string)|string) & ("a"|"b")) 201 } 202 issue763a: { 203 #A: { 204 v: ("a"|"b"|"c") 205 } 206 h: { 207 [string]: 〈1;#A〉 208 } 209 h: { 210 [=~"^b"]: (〈1;#A〉 & { 211 v: (*〈2;h〉.a.v|string) 212 }) 213 } 214 h: { 215 a: { 216 v: (*"a"|string) 217 } 218 } 219 h: { 220 baa: _ 221 } 222 h: { 223 boo: _ 224 } 225 } 226 }