Skip to content

Commit 938d270

Browse files
committed
internal/core/adt: add tests for Issue 3941
Issue #3941 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I7ba1bc5653cde4ede66e3598110720e091317aff Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1215642 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 3bc5784 commit 938d270

File tree

1 file changed

+197
-34
lines changed

1 file changed

+197
-34
lines changed

cue/testdata/cycle/comprehension.txtar

Lines changed: 197 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -386,23 +386,43 @@ issue3903: full: {
386386
]
387387
}
388388
}
389+
-- issue3941.cue --
390+
issue3941: full: {
391+
#Metadata: name: string
392+
#Resource: metadata: #Metadata
393+
394+
out: {
395+
_metadata: name: "foo"
396+
resource: [string]: [string]: #Resource
397+
398+
_names: [_metadata.name]
399+
400+
for name in _names {
401+
resource: level1: (name): {
402+
metadata: _metadata
403+
}
404+
}
405+
}
406+
}
389407
-- out/evalalpha/stats --
390-
Leaks: 978
408+
Leaks: 996
391409
Freed: 0
392410
Reused: 0
393-
Allocs: 978
411+
Allocs: 996
394412
Retain: 0
395413

396-
Unifications: 607
397-
Conjuncts: 1677
414+
Unifications: 625
415+
Conjuncts: 1705
398416
Disjuncts: 202
399417

400418
CloseIDElems: 10137
401-
NumCloseIDs: 846
419+
NumCloseIDs: 850
402420
-- out/evalalpha --
403421
Errors:
404422
selfReferential.insertionError.A: adding field foo3 not allowed as field set was already referenced:
405423
./in.cue:122:14
424+
issue3941.full.out.resource.level1.foo.metadata: adding field name not allowed as field set was already referenced:
425+
./issue3941.cue:3:23
406426

407427
Result:
408428
(_|_){
@@ -1064,12 +1084,46 @@ Result:
10641084
}
10651085
}
10661086
}
1087+
issue3941: (_|_){
1088+
// [eval]
1089+
full: (_|_){
1090+
// [eval]
1091+
#Metadata: (#struct){
1092+
name: (string){ string }
1093+
}
1094+
#Resource: (#struct){
1095+
metadata: ~(issue3941.full.#Metadata)
1096+
}
1097+
out: (_|_){
1098+
// [eval]
1099+
_metadata: (struct){
1100+
name: (string){ "foo" }
1101+
}
1102+
resource: (_|_){
1103+
// [eval]
1104+
level1: (_|_){
1105+
// [eval]
1106+
foo: (_|_){
1107+
// [eval]
1108+
metadata: (_|_){
1109+
// [eval] issue3941.full.out.resource.level1.foo.metadata: adding field name not allowed as field set was already referenced:
1110+
// ./issue3941.cue:3:23
1111+
}
1112+
}
1113+
}
1114+
}
1115+
_names: (#list){
1116+
0: (string){ "foo" }
1117+
}
1118+
}
1119+
}
1120+
}
10671121
}
10681122
-- diff/-out/evalalpha<==>+out/eval --
10691123
diff old new
10701124
--- old
10711125
+++ new
1072-
@@ -1,13 +1,6 @@
1126+
@@ -1,13 +1,8 @@
10731127
Errors:
10741128
-selfReferential.insertionError.A: field foo3 not allowed by earlier comprehension or reference cycle
10751129
-issue2310.original.#sub.#_1.#_1.#_1: structural cycle:
@@ -1082,10 +1136,12 @@ diff old new
10821136
- ./in.cue:347:21
10831137
+selfReferential.insertionError.A: adding field foo3 not allowed as field set was already referenced:
10841138
+ ./in.cue:122:14
1139+
+issue3941.full.out.resource.level1.foo.metadata: adding field name not allowed as field set was already referenced:
1140+
+ ./issue3941.cue:3:23
10851141

10861142
Result:
10871143
(_|_){
1088-
@@ -27,7 +20,9 @@
1144+
@@ -27,7 +22,9 @@
10891145
B: (struct){
10901146
a: (struct){
10911147
parent: (string){ "" }
@@ -1096,7 +1152,7 @@ diff old new
10961152
}
10971153
}
10981154
}
1099-
@@ -60,17 +55,12 @@
1155+
@@ -60,17 +57,12 @@
11001156
}
11011157
}
11021158
_e: (#struct){
@@ -1120,7 +1176,7 @@ diff old new
11201176
}
11211177
}
11221178
e: (#struct){
1123-
@@ -84,12 +74,7 @@
1179+
@@ -84,12 +76,7 @@
11241180
}
11251181
f2: (#struct){
11261182
a: (#struct){
@@ -1134,7 +1190,7 @@ diff old new
11341190
}
11351191
}
11361192
}
1137-
@@ -135,9 +120,9 @@
1193+
@@ -135,9 +122,9 @@
11381194
insertionError: (_|_){
11391195
// [eval]
11401196
A: (_|_){
@@ -1146,7 +1202,7 @@ diff old new
11461202
}
11471203
}
11481204
acrossOr: (struct){
1149-
@@ -405,10 +390,8 @@
1205+
@@ -405,10 +392,8 @@
11501206
issue2367: (struct){
11511207
a: (_){ _ }
11521208
}
@@ -1159,7 +1215,7 @@ diff old new
11591215
#s: (_|_){
11601216
// [incomplete] issue2310.original.#s: error in call to strings.Replace: non-concrete value string:
11611217
// ./in.cue:318:46
1162-
@@ -418,14 +401,128 @@
1218+
@@ -418,14 +403,128 @@
11631219
#_3: (string){ string }
11641220
}
11651221
#sub: (_|_){
@@ -1296,7 +1352,7 @@ diff old new
12961352
}
12971353
#subs: (#list){
12981354
0: (_|_){
1299-
@@ -432,33 +529,62 @@
1355+
@@ -432,33 +531,62 @@
13001356
// [incomplete] issue2310.original.#subs.0: error in call to strings.Replace: non-concrete value string:
13011357
// ./in.cue:318:46
13021358
// ./in.cue:318:12
@@ -1372,7 +1428,7 @@ diff old new
13721428
}
13731429
#s: (_|_){
13741430
// [incomplete] issue2310.reduced.#s: non-concrete value string in operand to +:
1375-
@@ -496,9 +622,6 @@
1431+
@@ -496,9 +624,6 @@
13761432
}
13771433
full: (struct){
13781434
s1: (#struct){
@@ -1382,7 +1438,7 @@ diff old new
13821438
_deps: (#list){
13831439
0: (#struct){
13841440
_local: (#list){
1385-
@@ -511,6 +634,9 @@
1441+
@@ -511,6 +636,9 @@
13861442
}
13871443
}
13881444
}
@@ -1392,42 +1448,85 @@ diff old new
13921448
objs: (#list){
13931449
0: (string){ "s1 local" }
13941450
1: (string){ "s2 local" }
1451+
@@ -536,25 +664,30 @@
1452+
}
1453+
}
1454+
}
1455+
- issue3941: (struct){
1456+
- full: (struct){
1457+
+ issue3941: (_|_){
1458+
+ // [eval]
1459+
+ full: (_|_){
1460+
+ // [eval]
1461+
#Metadata: (#struct){
1462+
name: (string){ string }
1463+
}
1464+
#Resource: (#struct){
1465+
- metadata: (#struct){
1466+
- name: (string){ string }
1467+
- }
1468+
- }
1469+
- out: (struct){
1470+
+ metadata: ~(issue3941.full.#Metadata)
1471+
+ }
1472+
+ out: (_|_){
1473+
+ // [eval]
1474+
_metadata: (struct){
1475+
name: (string){ "foo" }
1476+
}
1477+
- resource: (struct){
1478+
- level1: (struct){
1479+
- foo: (#struct){
1480+
- metadata: (#struct){
1481+
- name: (string){ "foo" }
1482+
+ resource: (_|_){
1483+
+ // [eval]
1484+
+ level1: (_|_){
1485+
+ // [eval]
1486+
+ foo: (_|_){
1487+
+ // [eval]
1488+
+ metadata: (_|_){
1489+
+ // [eval] issue3941.full.out.resource.level1.foo.metadata: adding field name not allowed as field set was already referenced:
1490+
+ // ./issue3941.cue:3:23
1491+
}
1492+
}
1493+
}
13951494
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
13961495
diff old new
13971496
--- old
13981497
+++ new
13991498
@@ -1,9 +1,12 @@
1400-
-Leaks: 74
1401-
-Freed: 1367
1402-
-Reused: 1341
1499+
-Leaks: 75
1500+
-Freed: 1383
1501+
-Reused: 1358
14031502
-Allocs: 100
1404-
-Retain: 478
1503+
-Retain: 479
14051504
-
1406-
-Unifications: 953
1407-
-Conjuncts: 2946
1408-
-Disjuncts: 1686
1409-
+Leaks: 978
1505+
-Unifications: 970
1506+
-Conjuncts: 2973
1507+
-Disjuncts: 1704
1508+
+Leaks: 996
14101509
+Freed: 0
14111510
+Reused: 0
1412-
+Allocs: 978
1511+
+Allocs: 996
14131512
+Retain: 0
14141513
+
1415-
+Unifications: 607
1416-
+Conjuncts: 1677
1514+
+Unifications: 625
1515+
+Conjuncts: 1705
14171516
+Disjuncts: 202
14181517
+
14191518
+CloseIDElems: 10137
1420-
+NumCloseIDs: 846
1519+
+NumCloseIDs: 850
14211520
-- out/eval/stats --
1422-
Leaks: 74
1423-
Freed: 1367
1424-
Reused: 1341
1521+
Leaks: 75
1522+
Freed: 1383
1523+
Reused: 1358
14251524
Allocs: 100
1426-
Retain: 478
1525+
Retain: 479
14271526

1428-
Unifications: 953
1429-
Conjuncts: 2946
1430-
Disjuncts: 1686
1527+
Unifications: 970
1528+
Conjuncts: 2973
1529+
Disjuncts: 1704
14311530
-- diff/explanation --
14321531
B.a.children: now correctly marked as incomplete
14331532
-- out/eval --
@@ -1969,6 +2068,35 @@ Result:
19692068
}
19702069
}
19712070
}
2071+
issue3941: (struct){
2072+
full: (struct){
2073+
#Metadata: (#struct){
2074+
name: (string){ string }
2075+
}
2076+
#Resource: (#struct){
2077+
metadata: (#struct){
2078+
name: (string){ string }
2079+
}
2080+
}
2081+
out: (struct){
2082+
_metadata: (struct){
2083+
name: (string){ "foo" }
2084+
}
2085+
resource: (struct){
2086+
level1: (struct){
2087+
foo: (#struct){
2088+
metadata: (#struct){
2089+
name: (string){ "foo" }
2090+
}
2091+
}
2092+
}
2093+
}
2094+
_names: (#list){
2095+
0: (string){ "foo" }
2096+
}
2097+
}
2098+
}
2099+
}
19722100
}
19732101
-- out/compile --
19742102
--- in.cue
@@ -2585,3 +2713,38 @@ Result:
25852713
}
25862714
}
25872715
}
2716+
--- issue3941.cue
2717+
{
2718+
issue3941: {
2719+
full: {
2720+
#Metadata: {
2721+
name: string
2722+
}
2723+
#Resource: {
2724+
metadata: 〈1;#Metadata〉
2725+
}
2726+
out: {
2727+
_metadata: {
2728+
name: "foo"
2729+
}
2730+
resource: {
2731+
[string]: {
2732+
[string]: 〈3;#Resource〉
2733+
}
2734+
}
2735+
_names: [
2736+
〈1;_metadata〉.name,
2737+
]
2738+
for _, name in 〈0;_names〉 {
2739+
resource: {
2740+
level1: {
2741+
〈3;name〉: {
2742+
metadata: 〈5;_metadata〉
2743+
}
2744+
}
2745+
}
2746+
}
2747+
}
2748+
}
2749+
}
2750+
}

0 commit comments

Comments
 (0)