cuelang.org/go@v0.13.0/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){ |(*(int){ 5 }, (number){ >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 @@ -6,9 +6,9 @@ 118 r: (int){ |((int){ 1 }, (int){ 2 }) } 119 s: (int){ |(*(int){ 1 }, (int){ 2 }) } 120 s1: (#struct){ 121 - max: (number){ |(*(int){ 5 }, (number){ >5 }) } 122 - res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 123 min: (int){ 5 } 124 + max: (number){ |(*(int){ 5 }, (number){ >5 }) } 125 + res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 126 } 127 #Size: (#struct){ 128 max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) } 129 @@ -16,7 +16,7 @@ 130 min: (number){ |(*(int){ 1 }, (number){ >0 }) } 131 } 132 staged: (struct){ 133 - c: (string){ |(*(string){ "a" }, (string){ "b" }) } 134 + c: (string){ |(*(string){ "a" }, *(string){ "b" }) } 135 d: (string){ |(*(string){ "a" }, (string){ "b" }) } 136 } 137 issue763a: (struct){ 138 -- diff/explanation -- 139 The changes in default behavior as are shown here are according to spec, as is 140 described at the top of the file. These changes may pose too much of a problem 141 for the transition to the new evaluator, though. 142 UPDATE: we have made evalv3 a bit more in line with evalv2. Note how this 143 affects staged.c, though. 144 TODO(defaults): consider these cases with a potential default redesign. 145 -- diff/todo/p3 -- 146 Reordering. 147 -- out/eval -- 148 (struct){ 149 Q: (int){ |(*(int){ 1 }, (int){ int }) } 150 q: (int){ |(*(int){ 1 }, (int){ int }) } 151 P: (int){ 2 } 152 p: (int){ |(*(int){ 2 }, (int){ int }) } 153 r: (int){ |((int){ 1 }, (int){ 2 }) } 154 s: (int){ |(*(int){ 1 }, (int){ 2 }) } 155 s1: (#struct){ 156 max: (number){ |(*(int){ 5 }, (number){ >5 }) } 157 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 158 min: (int){ 5 } 159 } 160 #Size: (#struct){ 161 max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) } 162 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 163 min: (number){ |(*(int){ 1 }, (number){ >0 }) } 164 } 165 staged: (struct){ 166 c: (string){ |(*(string){ "a" }, (string){ "b" }) } 167 d: (string){ |(*(string){ "a" }, (string){ "b" }) } 168 } 169 issue763a: (struct){ 170 #A: (#struct){ 171 v: (string){ |((string){ "a" }, (string){ "b" }, (string){ "c" }) } 172 } 173 h: (struct){ 174 a: (#struct){ 175 v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 176 } 177 baa: (#struct){ 178 v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 179 } 180 boo: (#struct){ 181 v: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 182 } 183 } 184 } 185 } 186 -- out/compile -- 187 --- in.cue 188 { 189 Q: (*1|int) 190 q: (*〈0;Q〉|int) 191 P: (*1|int) 192 P: 2 193 p: (*〈0;P〉|int) 194 r: ((*3|(*1|2)) & (1|2)) 195 s: ((3|(*1|2)) & (1|2)) 196 s1: (〈0;#Size〉 & { 197 min: 5 198 }) 199 #Size: { 200 max: (>〈0;min〉|*〈0;min〉) 201 res: (&(int, >=0)|*0) 202 min: (>〈0;res〉|*(1 + 〈0;res〉)) 203 } 204 staged: { 205 c: (("a"|"b") & (*(*"a"|string)|string)) 206 d: ((*(*"a"|string)|string) & ("a"|"b")) 207 } 208 issue763a: { 209 #A: { 210 v: ("a"|"b"|"c") 211 } 212 h: { 213 [string]: 〈1;#A〉 214 } 215 h: { 216 [=~"^b"]: (〈1;#A〉 & { 217 v: (*〈2;h〉.a.v|string) 218 }) 219 } 220 h: { 221 a: { 222 v: (*"a"|string) 223 } 224 } 225 h: { 226 baa: _ 227 } 228 h: { 229 boo: _ 230 } 231 } 232 }