Skip to content

Commit 4e7564e

Browse files
committed
internal/core/adt: inline structs in schema are not closed by default
If an inline struct is used within a schema, it should only be treated as closed if it itself references a schema. This also applies to non-inline schema, but the algorithm handles that correctly. But because inline structs are created within a new context, and as a different root, this is not passed correctly. To deal with this, we turn off "FromDef" when handling inline values, and then check if the result itself is closed. Fixes #3853 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I830feec849fe4a33826b48cf1ebf6427e396425c Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1212290 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Matthew Sackman <[email protected]>
1 parent 5348d04 commit 4e7564e

File tree

3 files changed

+63
-123
lines changed

3 files changed

+63
-123
lines changed

cue/testdata/definitions/typocheck.txtar

+35-123
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Allocs: 508
306306
Retain: 0
307307

308308
Unifications: 403
309-
Conjuncts: 780
309+
Conjuncts: 781
310310
Disjuncts: 34
311311
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
312312
diff old new
@@ -328,7 +328,7 @@ diff old new
328328
-Conjuncts: 1396
329329
-Disjuncts: 901
330330
+Unifications: 403
331-
+Conjuncts: 780
331+
+Conjuncts: 781
332332
+Disjuncts: 34
333333
-- out/eval/stats --
334334
Leaks: 107
@@ -367,11 +367,6 @@ embed.simple.a.err: field not allowed:
367367
./in.cue:4:5
368368
embed.withIndirect.err: field not allowed:
369369
./in.cue:71:8
370-
embedInline.out.b.d: field not allowed:
371-
./inline.cue:8:4
372-
b.d: field not allowed:
373-
./inline.cue:23:12
374-
./inline.cue:20:4
375370
embed.openValidator.t2.a.b: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
376371
./validators.cue:21:5
377372
./validators.cue:21:12
@@ -636,42 +631,31 @@ Result:
636631
}
637632
}
638633
}
639-
embedInline: (_|_){
640-
// [eval]
634+
embedInline: (struct){
641635
#Schema: (#struct){
642636
a: (string){ "hello" }
643637
b: (#struct){
644638
c: (string){ "foo" }
645639
d: (string){ "never printed" }
646640
}
647641
}
648-
out: (_|_){
649-
// [eval]
642+
out: (#struct){
650643
a: (string){ "hello" }
651-
b: (_|_){
652-
// [eval]
644+
b: (#struct){
653645
c: (string){ "foo" }
654-
d: (_|_){
655-
// [eval] embedInline.out.b.d: field not allowed:
656-
// ./inline.cue:8:4
657-
}
646+
d: (string){ "never printed" }
658647
}
659648
}
660649
}
661-
issue3853: (_|_){
662-
// [eval]
650+
issue3853: (struct){
663651
#Schema: (#struct){
664652
a: (string){ "hello" }
665653
b: (#struct){
666654
c: (string){ "foo" }
667655
d: (string){ "never printed" }
668656
}
669657
}
670-
out: (_|_){
671-
// [eval] b.d: field not allowed:
672-
// ./inline.cue:23:12
673-
// ./inline.cue:20:4
674-
}
658+
out: (string){ "hello" }
675659
}
676660
issue3832: (#struct){
677661
_person: (struct){
@@ -1054,7 +1038,7 @@ Result:
10541038
diff old new
10551039
--- old
10561040
+++ new
1057-
@@ -1,81 +1,34 @@
1041+
@@ -1,81 +1,29 @@
10581042
Errors:
10591043
and.transitive.out.ok: field not allowed:
10601044
- ./in.cue:34:5
@@ -1133,15 +1117,10 @@ diff old new
11331117
- ./validators.cue:12:6
11341118
- ./validators.cue:17:5
11351119
- ./validators.cue:18:5
1136-
+embedInline.out.b.d: field not allowed:
1137-
+ ./inline.cue:8:4
1138-
+b.d: field not allowed:
1139-
+ ./inline.cue:23:12
1140-
+ ./inline.cue:20:4
11411120
embed.openValidator.t2.a.b: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
11421121
./validators.cue:21:5
11431122
./validators.cue:21:12
1144-
@@ -94,14 +47,11 @@
1123+
@@ -94,14 +42,11 @@
11451124
}
11461125
a: (_|_){
11471126
// [eval]
@@ -1157,7 +1136,7 @@ diff old new
11571136
}
11581137
}
11591138
andInStruct: (_|_){
1160-
@@ -111,14 +61,11 @@
1139+
@@ -111,14 +56,11 @@
11611140
}
11621141
a: (_|_){
11631142
// [eval]
@@ -1173,7 +1152,7 @@ diff old new
11731152
}
11741153
}
11751154
embedDefWithEmbedding: (_|_){
1176-
@@ -128,15 +75,11 @@
1155+
@@ -128,15 +70,11 @@
11771156
}
11781157
a: (_|_){
11791158
// [eval]
@@ -1190,7 +1169,7 @@ diff old new
11901169
}
11911170
}
11921171
embedComprehension: (_|_){
1193-
@@ -146,16 +89,11 @@
1172+
@@ -146,16 +84,11 @@
11941173
}
11951174
a: (_|_){
11961175
// [eval]
@@ -1208,7 +1187,7 @@ diff old new
12081187
}
12091188
}
12101189
fieldWithAnd: (_|_){
1211-
@@ -166,9 +104,6 @@
1190+
@@ -166,9 +99,6 @@
12121191
// [eval]
12131192
err: (_|_){
12141193
// [eval] embed.fieldWithAnd.a.err: field not allowed:
@@ -1218,7 +1197,7 @@ diff old new
12181197
// ./in.cue:20:13
12191198
}
12201199
}
1221-
@@ -179,20 +114,15 @@
1200+
@@ -179,20 +109,15 @@
12221201
a: (int){ int }
12231202
}
12241203
B: (struct){
@@ -1244,7 +1223,7 @@ diff old new
12441223
}
12451224
}
12461225
andEmbed: (_|_){
1247-
@@ -208,17 +138,11 @@
1226+
@@ -208,17 +133,11 @@
12481227
}
12491228
d: (_|_){
12501229
// [eval]
@@ -1263,7 +1242,7 @@ diff old new
12631242
}
12641243
}
12651244
nonDef: (struct){
1266-
@@ -227,12 +151,12 @@
1245+
@@ -227,12 +146,12 @@
12671246
a: (string){ string }
12681247
}
12691248
#Y: (#struct){
@@ -1280,7 +1259,7 @@ diff old new
12801259
}
12811260
}
12821261
}
1283-
@@ -242,12 +166,12 @@
1262+
@@ -242,12 +161,12 @@
12841263
Name: (string){ string }
12851264
}
12861265
#Step: (#struct){
@@ -1297,7 +1276,7 @@ diff old new
12971276
}
12981277
out: (#struct){
12991278
Name: (string){ "foo" }
1300-
@@ -257,21 +181,15 @@
1279+
@@ -257,21 +176,15 @@
13011280
}
13021281
withIndirect: (_|_){
13031282
// [eval]
@@ -1324,7 +1303,7 @@ diff old new
13241303
}
13251304
normalValidator: (_|_){
13261305
// [eval]
1327-
@@ -281,20 +199,17 @@
1306+
@@ -281,20 +194,17 @@
13281307
}
13291308
x: (_|_){
13301309
// [eval]
@@ -1348,7 +1327,7 @@ diff old new
13481327
#X: (_){
13491328
matchN(0, (#list){
13501329
})
1351-
@@ -301,17 +216,10 @@
1330+
@@ -301,17 +211,10 @@
13521331
a?: (int){ int }
13531332
b?: (int){ int }
13541333
}
@@ -1370,7 +1349,7 @@ diff old new
13701349
}
13711350
}
13721351
t2: (_|_){
1373-
@@ -330,10 +238,7 @@
1352+
@@ -330,10 +233,7 @@
13741353
// [eval]
13751354
b: (_|_){
13761355
// [eval] embed.openValidator.t2.a.b: conflicting values 1 and {b?:Y} (mismatched types int and struct):
@@ -1381,7 +1360,7 @@ diff old new
13811360
// ./validators.cue:24:8
13821361
// embed.openValidator.t2.a.b: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
13831362
// ./validators.cue:21:5
1384-
@@ -360,16 +265,11 @@
1363+
@@ -360,16 +260,11 @@
13851364
}
13861365
out: (_|_){
13871366
// [eval]
@@ -1399,7 +1378,7 @@ diff old new
13991378
}
14001379
}
14011380
transitiveWithEmbed: (_|_){
1402-
@@ -385,45 +285,50 @@
1381+
@@ -385,17 +280,11 @@
14031382
}
14041383
out: (_|_){
14051384
// [eval]
@@ -1414,78 +1393,11 @@ diff old new
14141393
- // ./in.cue:45:7
14151394
// ./in.cue:46:3
14161395
}
1417-
- }
1418-
- }
1419-
- }
1420-
- embedInline: (struct){
1421-
- #Schema: (#struct){
1422-
- a: (string){ "hello" }
1423-
- b: (#struct){
1424-
- c: (string){ "foo" }
1425-
- d: (string){ "never printed" }
1426-
- }
1427-
- }
1428-
- out: (#struct){
1429-
- a: (string){ "hello" }
1430-
- b: (#struct){
1431-
- c: (string){ "foo" }
1432-
- d: (string){ "never printed" }
1433-
- }
1434-
- }
1435-
- }
1436-
- issue3853: (struct){
1437-
- #Schema: (#struct){
1438-
- a: (string){ "hello" }
1439-
- b: (#struct){
1440-
- c: (string){ "foo" }
1441-
- d: (string){ "never printed" }
1442-
- }
1443-
- }
1444-
- out: (string){ "hello" }
14451396
+ a: (string){ string }
1446-
+ }
1447-
+ }
1448-
+ }
1449-
+ embedInline: (_|_){
1450-
+ // [eval]
1451-
+ #Schema: (#struct){
1452-
+ a: (string){ "hello" }
1453-
+ b: (#struct){
1454-
+ c: (string){ "foo" }
1455-
+ d: (string){ "never printed" }
1456-
+ }
1457-
+ }
1458-
+ out: (_|_){
1459-
+ // [eval]
1460-
+ a: (string){ "hello" }
1461-
+ b: (_|_){
1462-
+ // [eval]
1463-
+ c: (string){ "foo" }
1464-
+ d: (_|_){
1465-
+ // [eval] embedInline.out.b.d: field not allowed:
1466-
+ // ./inline.cue:8:4
1467-
+ }
1468-
+ }
1469-
+ }
1470-
+ }
1471-
+ issue3853: (_|_){
1472-
+ // [eval]
1473-
+ #Schema: (#struct){
1474-
+ a: (string){ "hello" }
1475-
+ b: (#struct){
1476-
+ c: (string){ "foo" }
1477-
+ d: (string){ "never printed" }
1478-
+ }
1479-
+ }
1480-
+ out: (_|_){
1481-
+ // [eval] b.d: field not allowed:
1482-
+ // ./inline.cue:23:12
1483-
+ // ./inline.cue:20:4
1484-
+ }
1397+
}
1398+
}
14851399
}
1486-
issue3832: (#struct){
1487-
_person: (struct){
1488-
@@ -440,8 +345,8 @@
1400+
@@ -440,8 +329,8 @@
14891401
// ./issue3832.cue:8:16
14901402
}
14911403
outFirstName: (_|_){
@@ -1496,7 +1408,7 @@ diff old new
14961408
}
14971409
}
14981410
}
1499-
@@ -451,35 +356,27 @@
1411+
@@ -451,35 +340,27 @@
15001412
}, (#struct){
15011413
pass: (#struct){
15021414
let self#1 = (_|_){
@@ -1542,7 +1454,7 @@ diff old new
15421454
pass: (#struct){
15431455
let self#1 = (#struct){
15441456
firstName: (string){ "Sam" }
1545-
@@ -486,18 +383,21 @@
1457+
@@ -486,18 +367,21 @@
15461458
}
15471459
outFirstName: (string){ "Sam" }
15481460
}
@@ -1576,7 +1488,7 @@ diff old new
15761488
}
15771489
issue3833: (struct){
15781490
out: (#struct){
1579-
@@ -573,12 +473,8 @@
1491+
@@ -573,12 +457,8 @@
15801492
globalField: (string){ string }
15811493
}
15821494
#Context: (#struct){
@@ -1591,7 +1503,7 @@ diff old new
15911503
}
15921504
out: (struct){
15931505
ingress: (#struct){
1594-
@@ -606,22 +502,22 @@
1506+
@@ -606,22 +486,22 @@
15951507
#Z: (#struct){
15961508
}
15971509
x: (#struct){
@@ -1630,7 +1542,7 @@ diff old new
16301542
z: (int){ 1 }
16311543
}
16321544
}
1633-
@@ -631,22 +527,22 @@
1545+
@@ -631,22 +511,22 @@
16341546
#Z: (#struct){
16351547
}
16361548
x: (#struct){
@@ -1669,7 +1581,7 @@ diff old new
16691581
z: (int){ 1 }
16701582
}
16711583
}
1672-
@@ -701,38 +597,11 @@
1584+
@@ -701,38 +581,11 @@
16731585
#Main: (#struct){
16741586
namespace: (string){ string }
16751587
output: (_|_){
@@ -1710,7 +1622,7 @@ diff old new
17101622
let base#6 = (#struct){
17111623
someMsg: (string){ string }
17121624
obs: (#struct){ |(*(#struct){
1713-
@@ -775,6 +644,19 @@
1625+
@@ -775,6 +628,19 @@
17141626
}
17151627
}
17161628
}
@@ -1730,7 +1642,7 @@ diff old new
17301642
}
17311643
}
17321644
out: (#struct){
1733-
@@ -804,17 +686,8 @@
1645+
@@ -804,17 +670,8 @@
17341646
// ./validators.cue:32:17
17351647
// disjunction.withErr.t1.out.b1.b2.b3: undefined field: mayExistLater:
17361648
// ./validators.cue:29:22

0 commit comments

Comments
 (0)