cuelang.org/go@v0.10.1/cue/testdata/eval/disjunctions.txtar (about) 1 -- in.cue -- 2 a: *1 | int 3 aa: *1 | *2 | int 4 5 b: { 6 name: "int" 7 val: int 8 } | { 9 name: "str" 10 val: string 11 } 12 13 d: b & {val: 3} 14 c: b & {name: "int", val: 3} 15 e: b & {val: "foo"} 16 f: b & {name: "str", val: 3} 17 18 // Disjunct elimination based on type. 19 e1: { 20 a: null | {bar: 2} 21 b: (a & {}).bar 22 } 23 24 d1: { 25 a: (null | {c: 1}) & {} 26 b: {} & (null | {c: 1}) 27 } 28 29 d2: { 30 a: ([...] | {c: 1}) & {} 31 b: {} & ([...] | {c: 1}) 32 } 33 34 d3: { 35 a: (string | {c: 1}) & {} 36 b: {} & (string | {c: 1}) 37 } 38 39 d4: { 40 a: (string | {c: 1}) & {} 41 b: {} & (string | {c: 1}) 42 } 43 44 d5: { 45 a: (number | {c: 1}) & {} 46 b: {} & (number | {c: 1}) 47 } 48 49 d6: { 50 a: (int | {c: 1}) & {} 51 b: {} & (int | {c: 1}) 52 } 53 54 t10: { 55 schema: test 56 schema: string | {name: string} 57 #A: {string | {name: string}} 58 59 test: name: "Test" 60 test: #A 61 } 62 63 t10: { 64 schema: string | {name: string} 65 schema: test 66 #A: {string | {name: string}} 67 68 test: name: "Test" 69 test: #A 70 } 71 72 t10: { 73 #A: {string | {name: string}} 74 75 test: name: "Test" 76 test: #A 77 78 schema: string | {name: string} 79 schema: test 80 } 81 82 t11: { 83 a: #A 84 a: b 85 86 b: #A & ["b"] 87 #A: ["a" | "b"] | {} 88 } 89 90 t11: { 91 b: #A & ["b"] 92 #A: ["a" | "b"] | {} 93 94 a: b 95 a: #A 96 } 97 98 cross: { 99 a: *"word" | string 100 a: string | *"word" 101 } 102 103 d100: { 104 // Should we allow a selector to imply a struct or list? Would be convenient. 105 // This would be a spec change. Disallow for now. 106 i: null | {bar: 2} 107 j: i.bar 108 } 109 110 issue641: { 111 #A: { 112 type: "a" 113 x: "" 114 } 115 116 #B: { 117 type: "b" 118 x: string 119 } 120 121 #C: { 122 b: #A | #B 123 } 124 125 e: [string]: #C & { 126 b: #A | #B 127 } 128 129 e: foobar: #C & { 130 b: #B & { 131 x: "foobar" 132 } 133 } 134 } 135 -- out/eval/stats -- 136 Leaks: 0 137 Freed: 304 138 Reused: 292 139 Allocs: 12 140 Retain: 0 141 142 Unifications: 147 143 Conjuncts: 564 144 Disjuncts: 304 145 -- out/evalalpha -- 146 Errors: 147 f.name: conflicting values "int" and "str": 148 ./in.cue:5:8 149 ./in.cue:15:15 150 f.val: conflicting values 3 and string (mismatched types int and string): 151 ./in.cue:9:8 152 ./in.cue:15:27 153 154 Result: 155 (_|_){ 156 // [eval] 157 a: (int){ |(*(int){ 1 }, (int){ int }) } 158 aa: (int){ |(*(int){ 1 }, *(int){ 2 }, (int){ int }) } 159 b: (struct){ |((struct){ 160 name: (string){ "int" } 161 val: (int){ int } 162 }, (struct){ 163 name: (string){ "str" } 164 val: (string){ string } 165 }) } 166 d: (struct){ 167 val: (int){ 3 } 168 name: (string){ "int" } 169 } 170 c: (struct){ 171 name: (string){ "int" } 172 val: (int){ 3 } 173 } 174 e: (struct){ 175 val: (string){ "foo" } 176 name: (string){ "str" } 177 } 178 f: (_|_){ 179 // [eval] f.name: conflicting values "int" and "str": 180 // ./in.cue:5:8 181 // ./in.cue:15:15 182 // f.val: conflicting values 3 and string (mismatched types int and string): 183 // ./in.cue:9:8 184 // ./in.cue:15:27 185 name: (string){ "str" } 186 val: (int){ 3 } 187 } 188 e1: (struct){ 189 a: ((null|struct)){ |((null){ null }, (struct){ 190 bar: (int){ 2 } 191 }) } 192 b: (int){ 2 } 193 } 194 d1: (struct){ 195 a: (struct){ 196 c: (int){ 1 } 197 } 198 b: (struct){ 199 c: (int){ 1 } 200 } 201 } 202 d2: (struct){ 203 a: (struct){ 204 c: (int){ 1 } 205 } 206 b: (struct){ 207 c: (int){ 1 } 208 } 209 } 210 d3: (struct){ 211 a: (struct){ 212 c: (int){ 1 } 213 } 214 b: (struct){ 215 c: (int){ 1 } 216 } 217 } 218 d4: (struct){ 219 a: (struct){ 220 c: (int){ 1 } 221 } 222 b: (struct){ 223 c: (int){ 1 } 224 } 225 } 226 d5: (struct){ 227 a: (struct){ 228 c: (int){ 1 } 229 } 230 b: (struct){ 231 c: (int){ 1 } 232 } 233 } 234 d6: (struct){ 235 a: (struct){ 236 c: (int){ 1 } 237 } 238 b: (struct){ 239 c: (int){ 1 } 240 } 241 } 242 t10: (struct){ 243 schema: (#struct){ 244 name: (string){ "Test" } 245 } 246 #A: ((string|struct)){ |((string){ string }, (#struct){ 247 name: (string){ string } 248 }) } 249 test: (#struct){ 250 name: (string){ "Test" } 251 } 252 } 253 t11: (struct){ 254 a: (#list){ 255 0: (string){ "b" } 256 } 257 b: (#list){ 258 0: (string){ "b" } 259 } 260 #A: ((list|struct)){ |((#list){ 261 0: (string){ |((string){ "a" }, (string){ "b" }) } 262 }, (#struct){ 263 }) } 264 } 265 cross: (struct){ 266 a: (string){ |(*(string){ "word" }, (string){ string }) } 267 } 268 d100: (struct){ 269 i: ((null|struct)){ |((null){ null }, (struct){ 270 bar: (int){ 2 } 271 }) } 272 j: (_|_){ 273 // [incomplete] d100.j: unresolved disjunction null | {bar:2} (type (null|struct)): 274 // ./in.cue:106:5 275 } 276 } 277 issue641: (struct){ 278 #A: (#struct){ 279 type: (string){ "a" } 280 x: (string){ "" } 281 } 282 #B: (#struct){ 283 type: (string){ "b" } 284 x: (string){ string } 285 } 286 #C: (#struct){ 287 b: (#struct){ |((#struct){ 288 type: (string){ "a" } 289 x: (string){ "" } 290 }, (#struct){ 291 type: (string){ "b" } 292 x: (string){ string } 293 }) } 294 } 295 e: (struct){ 296 foobar: (#struct){ 297 b: (#struct){ 298 x: (string){ "foobar" } 299 type: (string){ "b" } 300 } 301 } 302 } 303 } 304 } 305 -- diff/-out/evalalpha<==>+out/eval -- 306 diff old new 307 --- old 308 +++ new 309 @@ -1,12 +1,9 @@ 310 Errors: 311 -f: 2 errors in empty disjunction: 312 f.name: conflicting values "int" and "str": 313 ./in.cue:5:8 314 - ./in.cue:15:4 315 ./in.cue:15:15 316 f.val: conflicting values 3 and string (mismatched types int and string): 317 ./in.cue:9:8 318 - ./in.cue:15:4 319 ./in.cue:15:27 320 321 Result: 322 @@ -34,22 +31,14 @@ 323 name: (string){ "str" } 324 } 325 f: (_|_){ 326 - // [eval] f: 2 errors in empty disjunction: 327 - // f.name: conflicting values "int" and "str": 328 + // [eval] f.name: conflicting values "int" and "str": 329 // ./in.cue:5:8 330 - // ./in.cue:15:4 331 // ./in.cue:15:15 332 // f.val: conflicting values 3 and string (mismatched types int and string): 333 // ./in.cue:9:8 334 - // ./in.cue:15:4 335 // ./in.cue:15:27 336 name: (string){ "str" } 337 - val: (_|_){ 338 - // [eval] f.val: conflicting values 3 and string (mismatched types int and string): 339 - // ./in.cue:9:8 340 - // ./in.cue:15:4 341 - // ./in.cue:15:27 342 - } 343 + val: (int){ 3 } 344 } 345 e1: (struct){ 346 a: ((null|struct)){ |((null){ null }, (struct){ 347 @@ -161,8 +150,8 @@ 348 e: (struct){ 349 foobar: (#struct){ 350 b: (#struct){ 351 - type: (string){ "b" } 352 x: (string){ "foobar" } 353 + type: (string){ "b" } 354 } 355 } 356 } 357 -- diff/todo/p3 -- 358 f: Missing "errors in empty disjunction:" 359 Missing error positions. 360 It is probably okay to show name and val fields with original values, as long 361 as it is made clear that f does not unify with disjunctions and positions are 362 conveyed properly. 363 -- out/eval -- 364 Errors: 365 f: 2 errors in empty disjunction: 366 f.name: conflicting values "int" and "str": 367 ./in.cue:5:8 368 ./in.cue:15:4 369 ./in.cue:15:15 370 f.val: conflicting values 3 and string (mismatched types int and string): 371 ./in.cue:9:8 372 ./in.cue:15:4 373 ./in.cue:15:27 374 375 Result: 376 (_|_){ 377 // [eval] 378 a: (int){ |(*(int){ 1 }, (int){ int }) } 379 aa: (int){ |(*(int){ 1 }, *(int){ 2 }, (int){ int }) } 380 b: (struct){ |((struct){ 381 name: (string){ "int" } 382 val: (int){ int } 383 }, (struct){ 384 name: (string){ "str" } 385 val: (string){ string } 386 }) } 387 d: (struct){ 388 val: (int){ 3 } 389 name: (string){ "int" } 390 } 391 c: (struct){ 392 name: (string){ "int" } 393 val: (int){ 3 } 394 } 395 e: (struct){ 396 val: (string){ "foo" } 397 name: (string){ "str" } 398 } 399 f: (_|_){ 400 // [eval] f: 2 errors in empty disjunction: 401 // f.name: conflicting values "int" and "str": 402 // ./in.cue:5:8 403 // ./in.cue:15:4 404 // ./in.cue:15:15 405 // f.val: conflicting values 3 and string (mismatched types int and string): 406 // ./in.cue:9:8 407 // ./in.cue:15:4 408 // ./in.cue:15:27 409 name: (string){ "str" } 410 val: (_|_){ 411 // [eval] f.val: conflicting values 3 and string (mismatched types int and string): 412 // ./in.cue:9:8 413 // ./in.cue:15:4 414 // ./in.cue:15:27 415 } 416 } 417 e1: (struct){ 418 a: ((null|struct)){ |((null){ null }, (struct){ 419 bar: (int){ 2 } 420 }) } 421 b: (int){ 2 } 422 } 423 d1: (struct){ 424 a: (struct){ 425 c: (int){ 1 } 426 } 427 b: (struct){ 428 c: (int){ 1 } 429 } 430 } 431 d2: (struct){ 432 a: (struct){ 433 c: (int){ 1 } 434 } 435 b: (struct){ 436 c: (int){ 1 } 437 } 438 } 439 d3: (struct){ 440 a: (struct){ 441 c: (int){ 1 } 442 } 443 b: (struct){ 444 c: (int){ 1 } 445 } 446 } 447 d4: (struct){ 448 a: (struct){ 449 c: (int){ 1 } 450 } 451 b: (struct){ 452 c: (int){ 1 } 453 } 454 } 455 d5: (struct){ 456 a: (struct){ 457 c: (int){ 1 } 458 } 459 b: (struct){ 460 c: (int){ 1 } 461 } 462 } 463 d6: (struct){ 464 a: (struct){ 465 c: (int){ 1 } 466 } 467 b: (struct){ 468 c: (int){ 1 } 469 } 470 } 471 t10: (struct){ 472 schema: (#struct){ 473 name: (string){ "Test" } 474 } 475 #A: ((string|struct)){ |((string){ string }, (#struct){ 476 name: (string){ string } 477 }) } 478 test: (#struct){ 479 name: (string){ "Test" } 480 } 481 } 482 t11: (struct){ 483 a: (#list){ 484 0: (string){ "b" } 485 } 486 b: (#list){ 487 0: (string){ "b" } 488 } 489 #A: ((list|struct)){ |((#list){ 490 0: (string){ |((string){ "a" }, (string){ "b" }) } 491 }, (#struct){ 492 }) } 493 } 494 cross: (struct){ 495 a: (string){ |(*(string){ "word" }, (string){ string }) } 496 } 497 d100: (struct){ 498 i: ((null|struct)){ |((null){ null }, (struct){ 499 bar: (int){ 2 } 500 }) } 501 j: (_|_){ 502 // [incomplete] d100.j: unresolved disjunction null | {bar:2} (type (null|struct)): 503 // ./in.cue:106:5 504 } 505 } 506 issue641: (struct){ 507 #A: (#struct){ 508 type: (string){ "a" } 509 x: (string){ "" } 510 } 511 #B: (#struct){ 512 type: (string){ "b" } 513 x: (string){ string } 514 } 515 #C: (#struct){ 516 b: (#struct){ |((#struct){ 517 type: (string){ "a" } 518 x: (string){ "" } 519 }, (#struct){ 520 type: (string){ "b" } 521 x: (string){ string } 522 }) } 523 } 524 e: (struct){ 525 foobar: (#struct){ 526 b: (#struct){ 527 type: (string){ "b" } 528 x: (string){ "foobar" } 529 } 530 } 531 } 532 } 533 } 534 -- out/compile -- 535 --- in.cue 536 { 537 a: (*1|int) 538 aa: (*1|*2|int) 539 b: ({ 540 name: "int" 541 val: int 542 }|{ 543 name: "str" 544 val: string 545 }) 546 d: (〈0;b〉 & { 547 val: 3 548 }) 549 c: (〈0;b〉 & { 550 name: "int" 551 val: 3 552 }) 553 e: (〈0;b〉 & { 554 val: "foo" 555 }) 556 f: (〈0;b〉 & { 557 name: "str" 558 val: 3 559 }) 560 e1: { 561 a: (null|{ 562 bar: 2 563 }) 564 b: (〈0;a〉 & {}).bar 565 } 566 d1: { 567 a: ((null|{ 568 c: 1 569 }) & {}) 570 b: ({} & (null|{ 571 c: 1 572 })) 573 } 574 d2: { 575 a: (([ 576 ..., 577 ]|{ 578 c: 1 579 }) & {}) 580 b: ({} & ([ 581 ..., 582 ]|{ 583 c: 1 584 })) 585 } 586 d3: { 587 a: ((string|{ 588 c: 1 589 }) & {}) 590 b: ({} & (string|{ 591 c: 1 592 })) 593 } 594 d4: { 595 a: ((string|{ 596 c: 1 597 }) & {}) 598 b: ({} & (string|{ 599 c: 1 600 })) 601 } 602 d5: { 603 a: ((number|{ 604 c: 1 605 }) & {}) 606 b: ({} & (number|{ 607 c: 1 608 })) 609 } 610 d6: { 611 a: ((int|{ 612 c: 1 613 }) & {}) 614 b: ({} & (int|{ 615 c: 1 616 })) 617 } 618 t10: { 619 schema: 〈0;test〉 620 schema: (string|{ 621 name: string 622 }) 623 #A: { 624 (string|{ 625 name: string 626 }) 627 } 628 test: { 629 name: "Test" 630 } 631 test: 〈0;#A〉 632 } 633 t10: { 634 schema: (string|{ 635 name: string 636 }) 637 schema: 〈0;test〉 638 #A: { 639 (string|{ 640 name: string 641 }) 642 } 643 test: { 644 name: "Test" 645 } 646 test: 〈0;#A〉 647 } 648 t10: { 649 #A: { 650 (string|{ 651 name: string 652 }) 653 } 654 test: { 655 name: "Test" 656 } 657 test: 〈0;#A〉 658 schema: (string|{ 659 name: string 660 }) 661 schema: 〈0;test〉 662 } 663 t11: { 664 a: 〈0;#A〉 665 a: 〈0;b〉 666 b: (〈0;#A〉 & [ 667 "b", 668 ]) 669 #A: ([ 670 ("a"|"b"), 671 ]|{}) 672 } 673 t11: { 674 b: (〈0;#A〉 & [ 675 "b", 676 ]) 677 #A: ([ 678 ("a"|"b"), 679 ]|{}) 680 a: 〈0;b〉 681 a: 〈0;#A〉 682 } 683 cross: { 684 a: (*"word"|string) 685 a: (string|*"word") 686 } 687 d100: { 688 i: (null|{ 689 bar: 2 690 }) 691 j: 〈0;i〉.bar 692 } 693 issue641: { 694 #A: { 695 type: "a" 696 x: "" 697 } 698 #B: { 699 type: "b" 700 x: string 701 } 702 #C: { 703 b: (〈1;#A〉|〈1;#B〉) 704 } 705 e: { 706 [string]: (〈1;#C〉 & { 707 b: (〈2;#A〉|〈2;#B〉) 708 }) 709 } 710 e: { 711 foobar: (〈1;#C〉 & { 712 b: (〈2;#B〉 & { 713 x: "foobar" 714 }) 715 }) 716 } 717 } 718 }