cuelang.org/go@v0.10.1/cue/testdata/scalars/embed.txtar (about) 1 // Issue ##739 2 3 -- in.cue -- 4 import "strings" 5 6 intEmbed: { 7 a1: { 8 2 9 } 10 a2: { 11 v: { 12 3 13 #foo: a2.v + 1 14 } 15 w: v 16 x: v.#foo 17 } 18 a3: a1 + a2.v 19 } 20 21 listEmbed: { 22 a1: { 23 2 24 } 25 b3: { 26 [1, 2] 27 #foo: 1 28 } 29 b4: b3 + b3 30 b5: b3[1] 31 b6: b3[5] 32 b7: b4[a1] // 1 33 } 34 35 stringEmbed: { 36 s1: { 37 "foo" 38 #bar: "bar" 39 } 40 s2: [ s1, {s1.#bar, #baz: 4}] 41 s3: strings.Join(s2, "--") 42 } 43 44 outPattern: { 45 sum: { 46 out: #a + #b 47 #a: int 48 #b: int 49 } 50 used: sum & {#a: 1, #b: 3} 51 } 52 53 arithmetic: { 54 sum: { 55 #a + #b 56 #a: int 57 #b: int 58 } 59 a1: (sum & {_, #a: 1, #b: 3}) + 2 60 a2: 2 + (sum & {_, #a: 1, #b: 3}) 61 a3: 2 + (2 + (sum & {_, #a: 1, #b: 3})) 62 } 63 64 defCheck: { 65 a: { 66 #def: 1 67 } 68 b: a.#def 69 } 70 71 optionalExists: { 72 string | { 73 value?: string 74 75 if value != _|_ { 76 other: int 77 } 78 } 79 } 80 81 optionalCheck: { 82 thing: string | { 83 value?: string 84 85 if value != _|_ { 86 other: int 87 } 88 } 89 90 thing: { 91 value: "some string" 92 other: 3 93 } 94 } 95 96 hidden: { 97 issue794: { 98 _foo: "foo" 99 [_foo] 100 } 101 } 102 103 -- issue2113.cue -- 104 // In all these tests, embedded scalars should resolve without error. 105 merged: t1: p1: { 106 #fn: { #in2: _, _ } 107 #fn: { #in2: c1: string, #in2.c1 } 108 x: #fn & {#in2: {c1: "V 1"}, _} 109 } 110 merged: t1: p2: { 111 #fn: { #in2: c1: string, #in2.c1 } 112 #fn: { #in2: _, _ } 113 x: #fn & {#in2: {c1: "V 1"}, _} 114 } 115 merged: t1: p3: { 116 x: #fn & {#in2: {c1: "V 1"}, _} 117 #fn: { #in2: c1: string, #in2.c1 } 118 #fn: { #in2: _, _ } 119 } 120 merged: t2: p1: { 121 #fn: { #in2: {}, _ } 122 #fn: { #in2: c1: string, #in2.c1 } 123 x: #fn & {#in2: {c1: "V 1"}, _} 124 } 125 merged: t2: p2: { 126 #fn: { #in2: c1: string, #in2.c1 } 127 #fn: { #in2: {}, _ } 128 x: #fn & {#in2: {c1: "V 1"}, _} 129 } 130 merged: t2: p3: { 131 x: #fn & {#in2: {c1: "V 1"}, _} 132 #fn: { #in2: c1: string, #in2.c1 } 133 #fn: { #in2: {}, _ } 134 } 135 136 -- issue2163.cue -- 137 selfRefInEmbed: t1: { 138 #Func: { 139 #in: _ 140 _ 141 } 142 #fn: #Func 143 #fn: { 144 #in: _ 145 146 (#Func & { 147 _foo: #in 148 "buzz" 149 }) + "fiz" 150 } 151 } 152 153 -- out/eval/stats -- 154 Leaks: 11 155 Freed: 121 156 Reused: 114 157 Allocs: 18 158 Retain: 57 159 160 Unifications: 128 161 Conjuncts: 297 162 Disjuncts: 164 163 -- out/evalalpha -- 164 Errors: 165 listEmbed.b6: index out of range [5] with length 2: 166 ./in.cue:28:9 167 168 Result: 169 (_|_){ 170 // [eval] 171 intEmbed: (struct){ 172 a1: (int){ 2 } 173 a2: (struct){ 174 v: (int){ 175 3 176 #foo: (int){ 4 } 177 } 178 w: ~(intEmbed.a2.v) 179 x: (int){ 4 } 180 } 181 a3: (int){ 5 } 182 } 183 listEmbed: (_|_){ 184 // [eval] 185 a1: (int){ 2 } 186 b3: (#list){ 187 #foo: (int){ 1 } 188 0: (int){ 1 } 189 1: (int){ 2 } 190 } 191 b4: (#list){ 192 0: (int){ 1 } 193 1: (int){ 2 } 194 2: (int){ 1 } 195 3: (int){ 2 } 196 } 197 b5: (int){ 2 } 198 b6: (_|_){ 199 // [eval] listEmbed.b6: index out of range [5] with length 2: 200 // ./in.cue:28:9 201 } 202 b7: (int){ 1 } 203 } 204 stringEmbed: (struct){ 205 s1: (string){ 206 "foo" 207 #bar: (string){ "bar" } 208 } 209 s2: (#list){ 210 0: (string){ 211 "foo" 212 #bar: (string){ "bar" } 213 } 214 1: (string){ 215 "bar" 216 #baz: (int){ 4 } 217 } 218 } 219 s3: (string){ "foo--bar" } 220 } 221 outPattern: (struct){ 222 sum: (struct){ 223 out: (_|_){ 224 // [incomplete] outPattern.sum.out: non-concrete value int in operand to +: 225 // ./in.cue:43:8 226 // ./in.cue:44:8 227 } 228 #a: (int){ int } 229 #b: (int){ int } 230 } 231 used: (struct){ 232 #a: (int){ 1 } 233 #b: (int){ 3 } 234 out: (int){ 4 } 235 } 236 } 237 arithmetic: (struct){ 238 sum: (_|_){ 239 // [incomplete] arithmetic.sum: non-concrete value int in operand to +: 240 // ./in.cue:52:3 241 // ./in.cue:53:7 242 #a: (int){ int } 243 #b: (int){ int } 244 } 245 a1: (int){ 6 } 246 a2: (int){ 6 } 247 a3: (int){ 8 } 248 } 249 defCheck: (struct){ 250 a: (struct){ 251 #def: (int){ 1 } 252 } 253 b: (int){ 1 } 254 } 255 optionalExists: ((string|struct)){ |((string){ string }, (struct){ 256 value?: (string){ string } 257 }) } 258 optionalCheck: (struct){ 259 thing: (struct){ 260 value: (string){ "some string" } 261 other: (int){ 3 } 262 } 263 } 264 hidden: (struct){ 265 issue794: (#list){ 266 _foo: (string){ "foo" } 267 0: (string){ "foo" } 268 } 269 } 270 merged: (struct){ 271 t1: (struct){ 272 p1: (struct){ 273 #fn: (string){ 274 string 275 #in2: (#struct){ 276 c1: (string){ string } 277 } 278 } 279 x: (string){ 280 "V 1" 281 #in2: (#struct){ 282 c1: (string){ "V 1" } 283 } 284 } 285 } 286 p2: (struct){ 287 #fn: (string){ 288 string 289 #in2: (#struct){ 290 c1: (string){ string } 291 } 292 } 293 x: (string){ 294 "V 1" 295 #in2: (#struct){ 296 c1: (string){ "V 1" } 297 } 298 } 299 } 300 p3: (struct){ 301 x: (string){ 302 "V 1" 303 #in2: (#struct){ 304 c1: (string){ "V 1" } 305 } 306 } 307 #fn: (string){ 308 string 309 #in2: (#struct){ 310 c1: (string){ string } 311 } 312 } 313 } 314 } 315 t2: (struct){ 316 p1: (struct){ 317 #fn: (string){ 318 string 319 #in2: (#struct){ 320 c1: (string){ string } 321 } 322 } 323 x: (string){ 324 "V 1" 325 #in2: (#struct){ 326 c1: (string){ "V 1" } 327 } 328 } 329 } 330 p2: (struct){ 331 #fn: (string){ 332 string 333 #in2: (#struct){ 334 c1: (string){ string } 335 } 336 } 337 x: (string){ 338 "V 1" 339 #in2: (#struct){ 340 c1: (string){ "V 1" } 341 } 342 } 343 } 344 p3: (struct){ 345 x: (string){ 346 "V 1" 347 #in2: (#struct){ 348 c1: (string){ "V 1" } 349 } 350 } 351 #fn: (string){ 352 string 353 #in2: (#struct){ 354 c1: (string){ string } 355 } 356 } 357 } 358 } 359 } 360 selfRefInEmbed: (struct){ 361 t1: (struct){ 362 #Func: (_){ 363 _ 364 #in: (_){ _ } 365 } 366 #fn: (string){ 367 "buzzfiz" 368 #in: (_){ _ } 369 } 370 } 371 } 372 } 373 -- diff/-out/evalalpha<==>+out/eval -- 374 diff old new 375 --- old 376 +++ new 377 @@ -1,5 +1,5 @@ 378 Errors: 379 -listEmbed.b6: invalid list index 5 (out of bounds): 380 +listEmbed.b6: index out of range [5] with length 2: 381 ./in.cue:28:9 382 383 Result: 384 @@ -12,10 +12,7 @@ 385 3 386 #foo: (int){ 4 } 387 } 388 - w: (int){ 389 - 3 390 - #foo: (int){ 4 } 391 - } 392 + w: ~(intEmbed.a2.v) 393 x: (int){ 4 } 394 } 395 a3: (int){ 5 } 396 @@ -36,7 +33,7 @@ 397 } 398 b5: (int){ 2 } 399 b6: (_|_){ 400 - // [eval] listEmbed.b6: invalid list index 5 (out of bounds): 401 + // [eval] listEmbed.b6: index out of range [5] with length 2: 402 // ./in.cue:28:9 403 } 404 b7: (int){ 1 } 405 @@ -69,9 +66,9 @@ 406 #b: (int){ int } 407 } 408 used: (struct){ 409 - out: (int){ 4 } 410 #a: (int){ 1 } 411 #b: (int){ 3 } 412 + out: (int){ 4 } 413 } 414 } 415 arithmetic: (struct){ 416 -- diff/todo/p3 -- 417 Reordering. 418 -- diff/explanation -- 419 Improved error message. 420 -- out/eval -- 421 Errors: 422 listEmbed.b6: invalid list index 5 (out of bounds): 423 ./in.cue:28:9 424 425 Result: 426 (_|_){ 427 // [eval] 428 intEmbed: (struct){ 429 a1: (int){ 2 } 430 a2: (struct){ 431 v: (int){ 432 3 433 #foo: (int){ 4 } 434 } 435 w: (int){ 436 3 437 #foo: (int){ 4 } 438 } 439 x: (int){ 4 } 440 } 441 a3: (int){ 5 } 442 } 443 listEmbed: (_|_){ 444 // [eval] 445 a1: (int){ 2 } 446 b3: (#list){ 447 #foo: (int){ 1 } 448 0: (int){ 1 } 449 1: (int){ 2 } 450 } 451 b4: (#list){ 452 0: (int){ 1 } 453 1: (int){ 2 } 454 2: (int){ 1 } 455 3: (int){ 2 } 456 } 457 b5: (int){ 2 } 458 b6: (_|_){ 459 // [eval] listEmbed.b6: invalid list index 5 (out of bounds): 460 // ./in.cue:28:9 461 } 462 b7: (int){ 1 } 463 } 464 stringEmbed: (struct){ 465 s1: (string){ 466 "foo" 467 #bar: (string){ "bar" } 468 } 469 s2: (#list){ 470 0: (string){ 471 "foo" 472 #bar: (string){ "bar" } 473 } 474 1: (string){ 475 "bar" 476 #baz: (int){ 4 } 477 } 478 } 479 s3: (string){ "foo--bar" } 480 } 481 outPattern: (struct){ 482 sum: (struct){ 483 out: (_|_){ 484 // [incomplete] outPattern.sum.out: non-concrete value int in operand to +: 485 // ./in.cue:43:8 486 // ./in.cue:44:8 487 } 488 #a: (int){ int } 489 #b: (int){ int } 490 } 491 used: (struct){ 492 out: (int){ 4 } 493 #a: (int){ 1 } 494 #b: (int){ 3 } 495 } 496 } 497 arithmetic: (struct){ 498 sum: (_|_){ 499 // [incomplete] arithmetic.sum: non-concrete value int in operand to +: 500 // ./in.cue:52:3 501 // ./in.cue:53:7 502 #a: (int){ int } 503 #b: (int){ int } 504 } 505 a1: (int){ 6 } 506 a2: (int){ 6 } 507 a3: (int){ 8 } 508 } 509 defCheck: (struct){ 510 a: (struct){ 511 #def: (int){ 1 } 512 } 513 b: (int){ 1 } 514 } 515 optionalExists: ((string|struct)){ |((string){ string }, (struct){ 516 value?: (string){ string } 517 }) } 518 optionalCheck: (struct){ 519 thing: (struct){ 520 value: (string){ "some string" } 521 other: (int){ 3 } 522 } 523 } 524 hidden: (struct){ 525 issue794: (#list){ 526 _foo: (string){ "foo" } 527 0: (string){ "foo" } 528 } 529 } 530 merged: (struct){ 531 t1: (struct){ 532 p1: (struct){ 533 #fn: (string){ 534 string 535 #in2: (#struct){ 536 c1: (string){ string } 537 } 538 } 539 x: (string){ 540 "V 1" 541 #in2: (#struct){ 542 c1: (string){ "V 1" } 543 } 544 } 545 } 546 p2: (struct){ 547 #fn: (string){ 548 string 549 #in2: (#struct){ 550 c1: (string){ string } 551 } 552 } 553 x: (string){ 554 "V 1" 555 #in2: (#struct){ 556 c1: (string){ "V 1" } 557 } 558 } 559 } 560 p3: (struct){ 561 x: (string){ 562 "V 1" 563 #in2: (#struct){ 564 c1: (string){ "V 1" } 565 } 566 } 567 #fn: (string){ 568 string 569 #in2: (#struct){ 570 c1: (string){ string } 571 } 572 } 573 } 574 } 575 t2: (struct){ 576 p1: (struct){ 577 #fn: (string){ 578 string 579 #in2: (#struct){ 580 c1: (string){ string } 581 } 582 } 583 x: (string){ 584 "V 1" 585 #in2: (#struct){ 586 c1: (string){ "V 1" } 587 } 588 } 589 } 590 p2: (struct){ 591 #fn: (string){ 592 string 593 #in2: (#struct){ 594 c1: (string){ string } 595 } 596 } 597 x: (string){ 598 "V 1" 599 #in2: (#struct){ 600 c1: (string){ "V 1" } 601 } 602 } 603 } 604 p3: (struct){ 605 x: (string){ 606 "V 1" 607 #in2: (#struct){ 608 c1: (string){ "V 1" } 609 } 610 } 611 #fn: (string){ 612 string 613 #in2: (#struct){ 614 c1: (string){ string } 615 } 616 } 617 } 618 } 619 } 620 selfRefInEmbed: (struct){ 621 t1: (struct){ 622 #Func: (_){ 623 _ 624 #in: (_){ _ } 625 } 626 #fn: (string){ 627 "buzzfiz" 628 #in: (_){ _ } 629 } 630 } 631 } 632 } 633 -- out/compile -- 634 --- in.cue 635 { 636 intEmbed: { 637 a1: { 638 2 639 } 640 a2: { 641 v: { 642 3 643 #foo: (〈2;a2〉.v + 1) 644 } 645 w: 〈0;v〉 646 x: 〈0;v〉.#foo 647 } 648 a3: (〈0;a1〉 + 〈0;a2〉.v) 649 } 650 listEmbed: { 651 a1: { 652 2 653 } 654 b3: { 655 [ 656 1, 657 2, 658 ] 659 #foo: 1 660 } 661 b4: (〈0;b3〉 + 〈0;b3〉) 662 b5: 〈0;b3〉[1] 663 b6: 〈0;b3〉[5] 664 b7: 〈0;b4〉[〈0;a1〉] 665 } 666 stringEmbed: { 667 s1: { 668 "foo" 669 #bar: "bar" 670 } 671 s2: [ 672 〈1;s1〉, 673 { 674 〈2;s1〉.#bar 675 #baz: 4 676 }, 677 ] 678 s3: 〈import;strings〉.Join(〈0;s2〉, "--") 679 } 680 outPattern: { 681 sum: { 682 out: (〈0;#a〉 + 〈0;#b〉) 683 #a: int 684 #b: int 685 } 686 used: (〈0;sum〉 & { 687 #a: 1 688 #b: 3 689 }) 690 } 691 arithmetic: { 692 sum: { 693 (〈0;#a〉 + 〈0;#b〉) 694 #a: int 695 #b: int 696 } 697 a1: ((〈0;sum〉 & { 698 _ 699 #a: 1 700 #b: 3 701 }) + 2) 702 a2: (2 + (〈0;sum〉 & { 703 _ 704 #a: 1 705 #b: 3 706 })) 707 a3: (2 + (2 + (〈0;sum〉 & { 708 _ 709 #a: 1 710 #b: 3 711 }))) 712 } 713 defCheck: { 714 a: { 715 #def: 1 716 } 717 b: 〈0;a〉.#def 718 } 719 optionalExists: { 720 (string|{ 721 value?: string 722 if (〈0;value〉 != _|_(explicit error (_|_ literal) in source)) { 723 other: int 724 } 725 }) 726 } 727 optionalCheck: { 728 thing: (string|{ 729 value?: string 730 if (〈0;value〉 != _|_(explicit error (_|_ literal) in source)) { 731 other: int 732 } 733 }) 734 thing: { 735 value: "some string" 736 other: 3 737 } 738 } 739 hidden: { 740 issue794: { 741 _foo: "foo" 742 [ 743 〈1;_foo〉, 744 ] 745 } 746 } 747 } 748 --- issue2113.cue 749 { 750 merged: { 751 t1: { 752 p1: { 753 #fn: { 754 #in2: _ 755 _ 756 } 757 #fn: { 758 #in2: { 759 c1: string 760 } 761 〈0;#in2〉.c1 762 } 763 x: (〈0;#fn〉 & { 764 #in2: { 765 c1: "V 1" 766 } 767 _ 768 }) 769 } 770 } 771 } 772 merged: { 773 t1: { 774 p2: { 775 #fn: { 776 #in2: { 777 c1: string 778 } 779 〈0;#in2〉.c1 780 } 781 #fn: { 782 #in2: _ 783 _ 784 } 785 x: (〈0;#fn〉 & { 786 #in2: { 787 c1: "V 1" 788 } 789 _ 790 }) 791 } 792 } 793 } 794 merged: { 795 t1: { 796 p3: { 797 x: (〈0;#fn〉 & { 798 #in2: { 799 c1: "V 1" 800 } 801 _ 802 }) 803 #fn: { 804 #in2: { 805 c1: string 806 } 807 〈0;#in2〉.c1 808 } 809 #fn: { 810 #in2: _ 811 _ 812 } 813 } 814 } 815 } 816 merged: { 817 t2: { 818 p1: { 819 #fn: { 820 #in2: {} 821 _ 822 } 823 #fn: { 824 #in2: { 825 c1: string 826 } 827 〈0;#in2〉.c1 828 } 829 x: (〈0;#fn〉 & { 830 #in2: { 831 c1: "V 1" 832 } 833 _ 834 }) 835 } 836 } 837 } 838 merged: { 839 t2: { 840 p2: { 841 #fn: { 842 #in2: { 843 c1: string 844 } 845 〈0;#in2〉.c1 846 } 847 #fn: { 848 #in2: {} 849 _ 850 } 851 x: (〈0;#fn〉 & { 852 #in2: { 853 c1: "V 1" 854 } 855 _ 856 }) 857 } 858 } 859 } 860 merged: { 861 t2: { 862 p3: { 863 x: (〈0;#fn〉 & { 864 #in2: { 865 c1: "V 1" 866 } 867 _ 868 }) 869 #fn: { 870 #in2: { 871 c1: string 872 } 873 〈0;#in2〉.c1 874 } 875 #fn: { 876 #in2: {} 877 _ 878 } 879 } 880 } 881 } 882 } 883 --- issue2163.cue 884 { 885 selfRefInEmbed: { 886 t1: { 887 #Func: { 888 #in: _ 889 _ 890 } 891 #fn: 〈0;#Func〉 892 #fn: { 893 #in: _ 894 ((〈1;#Func〉 & { 895 _foo: 〈1;#in〉 896 "buzz" 897 }) + "fiz") 898 } 899 } 900 } 901 }