cuelang.org/go@v0.13.0/cue/testdata/eval/issue3330.txtar (about) 1 -- in.cue -- 2 import "list" 3 4 issue3330: { 5 #A: { 6 let empty = {} 7 8 // Reference to empty is within the definition that defines it. Closedness 9 // thus does not trigger. 10 field: null | { n: int } 11 field: empty & { n: 3 } 12 } 13 14 out: list.Concat([[#A]]) 15 } 16 17 eliminated: { 18 // This test case ensures a definition is only used for the empty struct. 19 // This ensures that the elimination of disjuncts is triggered, ensuring 20 // the code path that caused the panic in issue3330 is triggered even when 21 // the closedness bug that triggered it indirectly is fixed. 22 #empty: {} 23 x: null | { n: 3 } 24 x: #empty & { n: 3 } 25 out: len(x) 26 } 27 28 simplified: { 29 // This is a different take on the above bug that demonstrates the issue 30 // is only triggered after a definition is referenced. 31 #struct: { 32 field: { n: 3 } & g 33 g: {} 34 } 35 36 out: #struct & {} 37 } 38 -- out/eval/stats -- 39 Leaks: 1 40 Freed: 43 41 Reused: 34 42 Allocs: 10 43 Retain: 4 44 45 Unifications: 36 46 Conjuncts: 70 47 Disjuncts: 47 48 -- out/evalalpha -- 49 Errors: 50 eliminated.x: 2 errors in empty disjunction: 51 eliminated.x: conflicting values null and {} (mismatched types null and struct): 52 ./in.cue:21:10 53 ./in.cue:22:5 54 eliminated.x.n: field not allowed: 55 ./in.cue:22:14 56 ./in.cue:23:16 57 58 Result: 59 (_|_){ 60 // [eval] 61 issue3330: (struct){ 62 #A: (#struct){ 63 let empty#1 = (#struct){ 64 } 65 field: (#struct){ 66 n: (int){ 3 } 67 } 68 } 69 out: (#list){ 70 0: ~(issue3330.#A) 71 } 72 } 73 eliminated: (_|_){ 74 // [eval] 75 #empty: (#struct){ 76 } 77 x: (_|_){ 78 // [eval] eliminated.x: 2 errors in empty disjunction: 79 // eliminated.x: conflicting values null and {} (mismatched types null and struct): 80 // ./in.cue:21:10 81 // ./in.cue:22:5 82 // eliminated.x.n: field not allowed: 83 // ./in.cue:22:14 84 // ./in.cue:23:16 85 n: (int){ 3 } 86 } 87 out: (_|_){ 88 // [eval] eliminated.x: 2 errors in empty disjunction: 89 // eliminated.x: conflicting values null and {} (mismatched types null and struct): 90 // ./in.cue:21:10 91 // ./in.cue:22:5 92 // eliminated.x.n: field not allowed: 93 // ./in.cue:22:14 94 // ./in.cue:23:16 95 } 96 } 97 simplified: (struct){ 98 #struct: (#struct){ 99 field: (#struct){ 100 n: (int){ 3 } 101 } 102 g: (#struct){ 103 } 104 } 105 out: (#struct){ 106 field: (#struct){ 107 n: (int){ 3 } 108 } 109 g: (#struct){ 110 } 111 } 112 } 113 } 114 -- diff/-out/evalalpha<==>+out/eval -- 115 diff old new 116 --- old 117 +++ new 118 @@ -1,12 +1,10 @@ 119 Errors: 120 eliminated.x: 2 errors in empty disjunction: 121 -eliminated.x: conflicting values null and {n:3} (mismatched types null and struct): 122 +eliminated.x: conflicting values null and {} (mismatched types null and struct): 123 + ./in.cue:21:10 124 ./in.cue:22:5 125 - ./in.cue:23:14 126 eliminated.x.n: field not allowed: 127 - ./in.cue:21:10 128 ./in.cue:22:14 129 - ./in.cue:23:5 130 ./in.cue:23:16 131 132 Result: 133 @@ -21,13 +19,7 @@ 134 } 135 } 136 out: (#list){ 137 - 0: (#struct){ 138 - let empty#1 = (#struct){ 139 - } 140 - field: (#struct){ 141 - n: (int){ 3 } 142 - } 143 - } 144 + 0: ~(issue3330.#A) 145 } 146 } 147 eliminated: (_|_){ 148 @@ -36,31 +28,21 @@ 149 } 150 x: (_|_){ 151 // [eval] eliminated.x: 2 errors in empty disjunction: 152 - // eliminated.x: conflicting values null and {n:3} (mismatched types null and struct): 153 - // ./in.cue:22:5 154 - // ./in.cue:23:14 155 - // eliminated.x.n: field not allowed: 156 - // ./in.cue:21:10 157 - // ./in.cue:22:14 158 - // ./in.cue:23:5 159 - // ./in.cue:23:16 160 - n: (_|_){ 161 - // [eval] eliminated.x.n: field not allowed: 162 - // ./in.cue:21:10 163 - // ./in.cue:22:14 164 - // ./in.cue:23:5 165 - // ./in.cue:23:16 166 - } 167 + // eliminated.x: conflicting values null and {} (mismatched types null and struct): 168 + // ./in.cue:21:10 169 + // ./in.cue:22:5 170 + // eliminated.x.n: field not allowed: 171 + // ./in.cue:22:14 172 + // ./in.cue:23:16 173 + n: (int){ 3 } 174 } 175 out: (_|_){ 176 // [eval] eliminated.x: 2 errors in empty disjunction: 177 - // eliminated.x: conflicting values null and {n:3} (mismatched types null and struct): 178 - // ./in.cue:22:5 179 - // ./in.cue:23:14 180 - // eliminated.x.n: field not allowed: 181 - // ./in.cue:21:10 182 - // ./in.cue:22:14 183 - // ./in.cue:23:5 184 + // eliminated.x: conflicting values null and {} (mismatched types null and struct): 185 + // ./in.cue:21:10 186 + // ./in.cue:22:5 187 + // eliminated.x.n: field not allowed: 188 + // ./in.cue:22:14 189 // ./in.cue:23:16 190 } 191 } 192 -- diff/todo/p3 -- 193 Small differences in error output. 194 -- out/eval -- 195 Errors: 196 eliminated.x: 2 errors in empty disjunction: 197 eliminated.x: conflicting values null and {n:3} (mismatched types null and struct): 198 ./in.cue:22:5 199 ./in.cue:23:14 200 eliminated.x.n: field not allowed: 201 ./in.cue:21:10 202 ./in.cue:22:14 203 ./in.cue:23:5 204 ./in.cue:23:16 205 206 Result: 207 (_|_){ 208 // [eval] 209 issue3330: (struct){ 210 #A: (#struct){ 211 let empty#1 = (#struct){ 212 } 213 field: (#struct){ 214 n: (int){ 3 } 215 } 216 } 217 out: (#list){ 218 0: (#struct){ 219 let empty#1 = (#struct){ 220 } 221 field: (#struct){ 222 n: (int){ 3 } 223 } 224 } 225 } 226 } 227 eliminated: (_|_){ 228 // [eval] 229 #empty: (#struct){ 230 } 231 x: (_|_){ 232 // [eval] eliminated.x: 2 errors in empty disjunction: 233 // eliminated.x: conflicting values null and {n:3} (mismatched types null and struct): 234 // ./in.cue:22:5 235 // ./in.cue:23:14 236 // eliminated.x.n: field not allowed: 237 // ./in.cue:21:10 238 // ./in.cue:22:14 239 // ./in.cue:23:5 240 // ./in.cue:23:16 241 n: (_|_){ 242 // [eval] eliminated.x.n: field not allowed: 243 // ./in.cue:21:10 244 // ./in.cue:22:14 245 // ./in.cue:23:5 246 // ./in.cue:23:16 247 } 248 } 249 out: (_|_){ 250 // [eval] eliminated.x: 2 errors in empty disjunction: 251 // eliminated.x: conflicting values null and {n:3} (mismatched types null and struct): 252 // ./in.cue:22:5 253 // ./in.cue:23:14 254 // eliminated.x.n: field not allowed: 255 // ./in.cue:21:10 256 // ./in.cue:22:14 257 // ./in.cue:23:5 258 // ./in.cue:23:16 259 } 260 } 261 simplified: (struct){ 262 #struct: (#struct){ 263 field: (#struct){ 264 n: (int){ 3 } 265 } 266 g: (#struct){ 267 } 268 } 269 out: (#struct){ 270 field: (#struct){ 271 n: (int){ 3 } 272 } 273 g: (#struct){ 274 } 275 } 276 } 277 } 278 -- out/compile -- 279 --- in.cue 280 { 281 issue3330: { 282 #A: { 283 let empty#1 = {} 284 field: (null|{ 285 n: int 286 }) 287 field: (〈0;let empty#1〉 & { 288 n: 3 289 }) 290 } 291 out: 〈import;list〉.Concat([ 292 [ 293 〈2;#A〉, 294 ], 295 ]) 296 } 297 eliminated: { 298 #empty: {} 299 x: (null|{ 300 n: 3 301 }) 302 x: (〈0;#empty〉 & { 303 n: 3 304 }) 305 out: len(〈0;x〉) 306 } 307 simplified: { 308 #struct: { 309 field: ({ 310 n: 3 311 } & 〈0;g〉) 312 g: {} 313 } 314 out: (〈0;#struct〉 & {}) 315 } 316 }