this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue: add a regression test for a closedness bug fixed in evalv3

In the added test case, the struct with the "name" field is closed
as it is referenced via the parent definition,
so trying to insert new fields via unification should fail.

The new evaluator fixes this case, as can be seen in the eval diff.
It seems the old evaluator wasn't tracking closedness properly here.

Closes #1830.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I9f96baa377f2f5cd5ab66491f1e3ca112cd33ab9
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195009
Reviewed-by: Paul Jolly <paul@myitcv.io>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+181 -24
+181 -24
cue/testdata/definitions/fields.txtar
··· 187 187 V: #S 188 188 V: { c: e: 1 } // Should fail 189 189 } 190 + -- issue1830.cue -- 191 + issue1830: { 192 + #x: { 193 + y: { 194 + z?: { 195 + name: string 196 + } 197 + } 198 + } 199 + 200 + egs: { 201 + x1: (#x & {y: z: _}).y.z & { 202 + name: "blah" 203 + age1: 5 204 + } 205 + x2: (#x.y & {z: _}).z & { 206 + name: "blah" 207 + age2: 5 208 + } 209 + } 210 + } 190 211 -- out/eval/stats -- 191 - Leaks: 0 192 - Freed: 194 193 - Reused: 184 212 + Leaks: 3 213 + Freed: 210 214 + Reused: 203 194 215 Allocs: 10 195 - Retain: 14 216 + Retain: 19 196 217 197 - Unifications: 194 198 - Conjuncts: 353 199 - Disjuncts: 208 218 + Unifications: 213 219 + Conjuncts: 388 220 + Disjuncts: 229 200 221 -- out/evalalpha -- 201 222 Errors: 202 223 err.t2.V.c.e: field not allowed: ··· 226 247 err.t7.a.b: field not allowed: 227 248 ./in.cue:177:5 228 249 ./in.cue:178:5 250 + issue1830.egs.x1.age1: field not allowed: 251 + ./issue1830.cue:11:7 252 + ./issue1830.cue:13:4 253 + issue1830.egs.x2.age2: field not allowed: 254 + ./issue1830.cue:15:7 255 + ./issue1830.cue:17:4 229 256 230 257 Result: 231 258 (_|_){ ··· 631 658 } 632 659 } 633 660 } 661 + issue1830: (_|_){ 662 + // [eval] 663 + #x: (#struct){ 664 + y: (#struct){ 665 + z?: (#struct){ 666 + name: (string){ string } 667 + } 668 + } 669 + } 670 + egs: (_|_){ 671 + // [eval] 672 + x1: (_|_){ 673 + // [eval] 674 + name: (string){ "blah" } 675 + age1: (_|_){ 676 + // [eval] issue1830.egs.x1.age1: field not allowed: 677 + // ./issue1830.cue:11:7 678 + // ./issue1830.cue:13:4 679 + } 680 + } 681 + x2: (_|_){ 682 + // [eval] 683 + name: (string){ "blah" } 684 + age2: (_|_){ 685 + // [eval] issue1830.egs.x2.age2: field not allowed: 686 + // ./issue1830.cue:15:7 687 + // ./issue1830.cue:17:4 688 + } 689 + } 690 + } 691 + } 634 692 } 635 693 -- diff/-out/evalalpha<==>+out/eval -- 636 694 diff old new 637 695 --- old 638 696 +++ new 639 - @@ -1,60 +1,31 @@ 697 + @@ -1,60 +1,37 @@ 640 698 Errors: 641 699 -err.t1.a.disallowed: field not allowed: 642 700 - ./in.cue:128:10 ··· 706 764 +err.t7.a.b: field not allowed: 707 765 + ./in.cue:177:5 708 766 + ./in.cue:178:5 767 + +issue1830.egs.x1.age1: field not allowed: 768 + + ./issue1830.cue:11:7 769 + + ./issue1830.cue:13:4 770 + +issue1830.egs.x2.age2: field not allowed: 771 + + ./issue1830.cue:15:7 772 + + ./issue1830.cue:17:4 709 773 710 774 Result: 711 775 (_|_){ 712 - @@ -63,7 +34,7 @@ 776 + @@ -63,7 +40,7 @@ 713 777 // [eval] 714 778 t1: (struct){ 715 779 c: (#list){ ··· 718 782 b: (int){ int } 719 783 } 720 784 } 721 - @@ -72,7 +43,7 @@ 785 + @@ -72,7 +49,7 @@ 722 786 } 723 787 t2: (struct){ 724 788 #A: (_){ _ } ··· 727 791 f: (string){ "hi" } 728 792 } 729 793 } 730 - @@ -102,11 +73,11 @@ 794 + @@ -102,11 +79,11 @@ 731 795 } 732 796 } 733 797 W: (#struct){ ··· 744 808 } 745 809 } 746 810 } 747 - @@ -120,10 +91,7 @@ 811 + @@ -120,10 +97,7 @@ 748 812 // [eval] 749 813 c: (_|_){ 750 814 // [eval] ok.t5.x.c: field not allowed: ··· 755 819 // ./in.cue:41:5 756 820 } 757 821 } 758 - @@ -179,7 +147,7 @@ 822 + @@ -179,7 +153,7 @@ 759 823 } 760 824 t9: (struct){ 761 825 c: (#list){ ··· 764 828 b: (int){ int } 765 829 } 766 830 } 767 - @@ -188,7 +156,7 @@ 831 + @@ -188,7 +162,7 @@ 768 832 } 769 833 t10: (struct){ 770 834 #A: (_){ _ } ··· 773 837 f: (string){ "hi" } 774 838 } 775 839 } 776 - @@ -218,11 +186,11 @@ 840 + @@ -218,11 +192,11 @@ 777 841 } 778 842 } 779 843 W: (#struct){ ··· 790 854 } 791 855 } 792 856 } 793 - @@ -236,10 +204,7 @@ 857 + @@ -236,10 +210,7 @@ 794 858 // [eval] 795 859 c: (_|_){ 796 860 // [eval] ok.t13.x.c: field not allowed: ··· 801 865 // ./in.cue:112:5 802 866 } 803 867 } 804 - @@ -263,13 +228,12 @@ 868 + @@ -263,13 +234,12 @@ 805 869 } 806 870 a: (_|_){ 807 871 // [eval] ··· 816 880 } 817 881 } 818 882 t2: (_|_){ 819 - @@ -283,14 +247,11 @@ 883 + @@ -283,14 +253,11 @@ 820 884 // [eval] 821 885 c: (_|_){ 822 886 // [eval] ··· 832 896 } 833 897 } 834 898 } 835 - @@ -304,7 +265,6 @@ 899 + @@ -304,7 +271,6 @@ 836 900 // [eval] 837 901 c: (_|_){ 838 902 // [eval] err.t3.p1.a.c: field not allowed: ··· 840 904 // ./in.cue:141:5 841 905 // ./in.cue:142:5 842 906 } 843 - @@ -322,8 +282,6 @@ 907 + @@ -322,8 +288,6 @@ 844 908 // [eval] 845 909 c: (_|_){ 846 910 // [eval] err.t3.p2.a.b.c: field not allowed: ··· 849 913 // ./in.cue:148:8 850 914 } 851 915 } 852 - @@ -336,54 +294,47 @@ 916 + @@ -336,54 +300,47 @@ 853 917 // [eval] 854 918 b: (_|_){ 855 919 // [eval] ··· 937 1001 } 938 1002 } 939 1003 } 940 - @@ -433,17 +384,12 @@ 1004 + @@ -433,17 +390,12 @@ 941 1005 // [eval] 942 1006 e: (_|_){ 943 1007 // [eval] ··· 957 1021 } 958 1022 } 959 1023 } 960 - @@ -457,13 +403,12 @@ 1024 + @@ -457,13 +409,12 @@ 961 1025 } 962 1026 a: (_|_){ 963 1027 // [eval] ··· 972 1036 } 973 1037 } 974 1038 t8: (_|_){ 975 - @@ -477,14 +422,11 @@ 1039 + @@ -477,19 +428,17 @@ 976 1040 // [eval] 977 1041 c: (_|_){ 978 1042 // [eval] ··· 984 1048 - // ./in.cue:184:5 985 1049 // ./in.cue:185:10 986 1050 } 1051 + - } 1052 + - } 1053 + - } 1054 + - } 1055 + - issue1830: (struct){ 987 1056 + d: (int){ 1 } 1057 + + } 1058 + + } 1059 + + } 1060 + + } 1061 + + issue1830: (_|_){ 1062 + + // [eval] 1063 + #x: (#struct){ 1064 + y: (#struct){ 1065 + z?: (#struct){ 1066 + @@ -497,14 +446,25 @@ 988 1067 } 989 1068 } 990 1069 } 1070 + - egs: (struct){ 1071 + - x1: (struct){ 1072 + - name: (string){ "blah" } 1073 + - age1: (int){ 5 } 1074 + - } 1075 + - x2: (struct){ 1076 + - name: (string){ "blah" } 1077 + - age2: (int){ 5 } 1078 + + egs: (_|_){ 1079 + + // [eval] 1080 + + x1: (_|_){ 1081 + + // [eval] 1082 + + name: (string){ "blah" } 1083 + + age1: (_|_){ 1084 + + // [eval] issue1830.egs.x1.age1: field not allowed: 1085 + + // ./issue1830.cue:11:7 1086 + + // ./issue1830.cue:13:4 1087 + + } 1088 + + } 1089 + + x2: (_|_){ 1090 + + // [eval] 1091 + + name: (string){ "blah" } 1092 + + age2: (_|_){ 1093 + + // [eval] issue1830.egs.x2.age2: field not allowed: 1094 + + // ./issue1830.cue:15:7 1095 + + // ./issue1830.cue:17:4 1096 + + } 1097 + } 1098 + } 1099 + } 991 1100 -- diff/todo/p2 -- 992 1101 ok.t1.c.0: closedness probably incorrect: #R defines elements as type "top", 993 1102 which are not closed by definition. Probably does not matter for evaluation, ··· 999 1108 all: error positions and reordering. 1000 1109 -- diff/explanation -- 1001 1110 ok.t5 and ok.t13 retain semantics of v0.6 for now. 1111 + issue1830: the new evaluator correctly rejects inserting new fields in a closed struct 1002 1112 -- out/eval -- 1003 1113 Errors: 1004 1114 err.t1.a.disallowed: field not allowed: ··· 1491 1601 } 1492 1602 } 1493 1603 } 1604 + issue1830: (struct){ 1605 + #x: (#struct){ 1606 + y: (#struct){ 1607 + z?: (#struct){ 1608 + name: (string){ string } 1609 + } 1610 + } 1611 + } 1612 + egs: (struct){ 1613 + x1: (struct){ 1614 + name: (string){ "blah" } 1615 + age1: (int){ 5 } 1616 + } 1617 + x2: (struct){ 1618 + name: (string){ "blah" } 1619 + age2: (int){ 5 } 1620 + } 1621 + } 1622 + } 1494 1623 } 1495 1624 -- out/compile -- 1496 1625 --- in.cue ··· 1878 2007 } 1879 2008 } 1880 2009 } 2010 + --- issue1830.cue 2011 + { 2012 + issue1830: { 2013 + #x: { 2014 + y: { 2015 + z?: { 2016 + name: string 2017 + } 2018 + } 2019 + } 2020 + egs: { 2021 + x1: ((〈1;#x〉 & { 2022 + y: { 2023 + z: _ 2024 + } 2025 + }).y.z & { 2026 + name: "blah" 2027 + age1: 5 2028 + }) 2029 + x2: ((〈1;#x〉.y & { 2030 + z: _ 2031 + }).z & { 2032 + name: "blah" 2033 + age2: 5 2034 + }) 2035 + } 2036 + } 2037 + }