Skip to content

Commit 112c279

Browse files
committed
internal/core/adt: apply replacements from ancestors
Replacements from ancestors should be applied as well. Not doing so resulted in the breakage of 3833. Note that this regresses one test in 3834. This is not the test that was reported originally in the issue, as that was at the top level. Still, the issue is eitherway still open as not all cases were covered. Also note that this is a slow implementation. I tried a caching implementation, but this resulted in a lot of changes, so this seems safer, albeit slightly slower. Fixes #3833 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ib276be58ca91e25d6c501d85d7d63a6d65882d2b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211936 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 290590f commit 112c279

File tree

3 files changed

+89
-86
lines changed

3 files changed

+89
-86
lines changed

cue/testdata/definitions/issue3834.txtar

+49-23
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,29 @@ Disjuncts: 237
227227
}
228228
out: (bool){ true }
229229
}
230-
_a: (struct){
231-
foo: (bool){ true }
232-
}
233-
_b: (struct){
234-
y: (struct){
235-
}
236-
foo: (bool){ true }
237-
}
238-
concrete: (struct){
230+
_a: (struct){ |((struct){
231+
foo: (bool){ true }
232+
}, (#struct){
233+
foo: (bool){ true }
234+
y!: (struct){
235+
z?: (_){ _ }
236+
}
237+
}) }
238+
_b: (struct){ |((struct){
239+
y: (struct){
240+
}
241+
foo: (bool){ true }
242+
}, (#struct){
243+
y: (struct){
244+
z?: (_){ _ }
245+
}
246+
foo: (bool){ true }
247+
}) }
248+
concrete: (_|_){
249+
// [incomplete] concrete: unresolved disjunction {y:{},foo:true} | {y:{z?:_},foo:true} (type struct):
250+
// ./in.cue:6:12
239251
}
240-
isTrue: (bool){ true }
252+
isTrue: (bool){ false }
241253
}
242254
-- diff/-out/evalalpha<==>+out/eval --
243255
diff old new
@@ -248,8 +260,10 @@ diff old new
248260
}
249261
_b: (struct){
250262
- foo: (bool){ true }
251-
y: (struct){
252-
}
263+
- y: (struct){
264+
- }
265+
+ y: (struct){
266+
+ }
253267
+ foo: (bool){ true }
254268
}
255269
concrete: (struct){
@@ -453,7 +467,7 @@ diff old new
453467
}
454468
out: (bool){ true }
455469
}
456-
@@ -137,10 +150,21 @@
470+
@@ -137,10 +150,33 @@
457471
Foo: (bool){ true }
458472
}
459473
_dataWithExtra: (#struct){
@@ -464,17 +478,29 @@ diff old new
464478
}
465479
out: (bool){ true }
466480
}
467-
+ _a: (struct){
468-
+ foo: (bool){ true }
469-
+ }
470-
+ _b: (struct){
471-
+ y: (struct){
472-
+ }
473-
+ foo: (bool){ true }
474-
+ }
475-
+ concrete: (struct){
481+
+ _a: (struct){ |((struct){
482+
+ foo: (bool){ true }
483+
+ }, (#struct){
484+
+ foo: (bool){ true }
485+
+ y!: (struct){
486+
+ z?: (_){ _ }
487+
+ }
488+
+ }) }
489+
+ _b: (struct){ |((struct){
490+
+ y: (struct){
491+
+ }
492+
+ foo: (bool){ true }
493+
+ }, (#struct){
494+
+ y: (struct){
495+
+ z?: (_){ _ }
496+
+ }
497+
+ foo: (bool){ true }
498+
+ }) }
499+
+ concrete: (_|_){
500+
+ // [incomplete] concrete: unresolved disjunction {y:{},foo:true} | {y:{z?:_},foo:true} (type struct):
501+
+ // ./in.cue:6:12
476502
+ }
477-
+ isTrue: (bool){ true }
503+
+ isTrue: (bool){ false }
478504
}
479505
-- diff/todo/p1 --
480506
*.concrete: several fields where there is still an disjunction

cue/testdata/definitions/typocheck.txtar

+30-61
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ embed.simple.a.err: field not allowed:
261261
./in.cue:4:5
262262
embed.withIndirect.err: field not allowed:
263263
./in.cue:71:8
264-
issue3833.out.a.b: field not allowed:
265-
./issue3833.cue:4:6
266-
./issue3833.cue:10:3
267264
embed.openValidator.t2.a.b: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
268265
./validators.cue:21:5
269266
./validators.cue:21:12
@@ -597,17 +594,10 @@ Result:
597594
}
598595
results: ~(issue3832._assert.pass)
599596
}
600-
issue3833: (_|_){
601-
// [eval]
602-
out: (_|_){
603-
// [eval]
604-
a: (_|_){
605-
// [eval]
606-
b: (_|_){
607-
// [eval] issue3833.out.a.b: field not allowed:
608-
// ./issue3833.cue:4:6
609-
// ./issue3833.cue:10:3
610-
}
597+
issue3833: (struct){
598+
out: (#struct){
599+
a: (#struct){
600+
b: (string){ "foo" }
611601
c: (string){ "foo" }
612602
}
613603
}
@@ -788,7 +778,7 @@ Result:
788778
diff old new
789779
--- old
790780
+++ new
791-
@@ -1,81 +1,32 @@
781+
@@ -1,81 +1,29 @@
792782
Errors:
793783
and.transitive.out.ok: field not allowed:
794784
- ./in.cue:34:5
@@ -867,13 +857,10 @@ diff old new
867857
- ./validators.cue:12:6
868858
- ./validators.cue:17:5
869859
- ./validators.cue:18:5
870-
+issue3833.out.a.b: field not allowed:
871-
+ ./issue3833.cue:4:6
872-
+ ./issue3833.cue:10:3
873860
embed.openValidator.t2.a.b: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
874861
./validators.cue:21:5
875862
./validators.cue:21:12
876-
@@ -94,14 +45,11 @@
863+
@@ -94,14 +42,11 @@
877864
}
878865
a: (_|_){
879866
// [eval]
@@ -889,7 +876,7 @@ diff old new
889876
}
890877
}
891878
andInStruct: (_|_){
892-
@@ -111,14 +59,11 @@
879+
@@ -111,14 +56,11 @@
893880
}
894881
a: (_|_){
895882
// [eval]
@@ -905,7 +892,7 @@ diff old new
905892
}
906893
}
907894
embedDefWithEmbedding: (_|_){
908-
@@ -128,15 +73,11 @@
895+
@@ -128,15 +70,11 @@
909896
}
910897
a: (_|_){
911898
// [eval]
@@ -922,7 +909,7 @@ diff old new
922909
}
923910
}
924911
embedComprehension: (_|_){
925-
@@ -146,16 +87,11 @@
912+
@@ -146,16 +84,11 @@
926913
}
927914
a: (_|_){
928915
// [eval]
@@ -940,7 +927,7 @@ diff old new
940927
}
941928
}
942929
fieldWithAnd: (_|_){
943-
@@ -166,9 +102,6 @@
930+
@@ -166,9 +99,6 @@
944931
// [eval]
945932
err: (_|_){
946933
// [eval] embed.fieldWithAnd.a.err: field not allowed:
@@ -950,7 +937,7 @@ diff old new
950937
// ./in.cue:20:13
951938
}
952939
}
953-
@@ -179,20 +112,15 @@
940+
@@ -179,20 +109,15 @@
954941
a: (int){ int }
955942
}
956943
B: (struct){
@@ -976,7 +963,7 @@ diff old new
976963
}
977964
}
978965
andEmbed: (_|_){
979-
@@ -208,17 +136,11 @@
966+
@@ -208,17 +133,11 @@
980967
}
981968
d: (_|_){
982969
// [eval]
@@ -995,7 +982,7 @@ diff old new
995982
}
996983
}
997984
nonDef: (struct){
998-
@@ -227,12 +149,12 @@
985+
@@ -227,12 +146,12 @@
999986
a: (string){ string }
1000987
}
1001988
#Y: (#struct){
@@ -1012,7 +999,7 @@ diff old new
1012999
}
10131000
}
10141001
}
1015-
@@ -242,12 +164,12 @@
1002+
@@ -242,12 +161,12 @@
10161003
Name: (string){ string }
10171004
}
10181005
#Step: (#struct){
@@ -1029,7 +1016,7 @@ diff old new
10291016
}
10301017
out: (#struct){
10311018
Name: (string){ "foo" }
1032-
@@ -257,21 +179,15 @@
1019+
@@ -257,21 +176,15 @@
10331020
}
10341021
withIndirect: (_|_){
10351022
// [eval]
@@ -1056,7 +1043,7 @@ diff old new
10561043
}
10571044
normalValidator: (_|_){
10581045
// [eval]
1059-
@@ -281,20 +197,17 @@
1046+
@@ -281,20 +194,17 @@
10601047
}
10611048
x: (_|_){
10621049
// [eval]
@@ -1080,7 +1067,7 @@ diff old new
10801067
#X: (_){
10811068
matchN(0, (#list){
10821069
})
1083-
@@ -301,17 +214,10 @@
1070+
@@ -301,17 +211,10 @@
10841071
a?: (int){ int }
10851072
b?: (int){ int }
10861073
}
@@ -1102,7 +1089,7 @@ diff old new
11021089
}
11031090
}
11041091
t2: (_|_){
1105-
@@ -330,10 +236,7 @@
1092+
@@ -330,10 +233,7 @@
11061093
// [eval]
11071094
b: (_|_){
11081095
// [eval] embed.openValidator.t2.a.b: conflicting values 1 and {b?:Y} (mismatched types int and struct):
@@ -1113,7 +1100,7 @@ diff old new
11131100
// ./validators.cue:24:8
11141101
// embed.openValidator.t2.a.b: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
11151102
// ./validators.cue:21:5
1116-
@@ -360,16 +263,11 @@
1103+
@@ -360,16 +260,11 @@
11171104
}
11181105
out: (_|_){
11191106
// [eval]
@@ -1131,7 +1118,7 @@ diff old new
11311118
}
11321119
}
11331120
transitiveWithEmbed: (_|_){
1134-
@@ -385,17 +283,11 @@
1121+
@@ -385,17 +280,11 @@
11351122
}
11361123
out: (_|_){
11371124
// [eval]
@@ -1150,7 +1137,7 @@ diff old new
11501137
}
11511138
}
11521139
}
1153-
@@ -414,8 +306,8 @@
1140+
@@ -414,8 +303,8 @@
11541141
// ./issue3832.cue:8:16
11551142
}
11561143
outFirstName: (_|_){
@@ -1161,7 +1148,7 @@ diff old new
11611148
}
11621149
}
11631150
}
1164-
@@ -425,21 +317,34 @@
1151+
@@ -425,21 +314,34 @@
11651152
}, (#struct){
11661153
pass: (#struct){
11671154
let self#1 = (_|_){
@@ -1201,7 +1188,7 @@ diff old new
12011188
_subject: (#struct){
12021189
in: (_){ _ }
12031190
out: (#struct){
1204-
@@ -448,35 +353,24 @@
1191+
@@ -448,30 +350,12 @@
12051192
// ./issue3832.cue:8:16
12061193
}
12071194
outFirstName: (_|_){
@@ -1229,33 +1216,16 @@ diff old new
12291216
- }
12301217
- outFirstName: (string){ "Sam" }
12311218
- }
1232-
- }
1233-
- issue3833: (struct){
1234-
- out: (#struct){
1235-
- a: (#struct){
1236-
- b: (string){ "foo" }
12371219
+ // [incomplete] issue3832._subject.out.outFirstName: undefined field: firstName:
12381220
+ // ./issue3832.cue:9:24
12391221
+ }
12401222
+ }
12411223
+ }
12421224
+ results: ~(issue3832._assert.pass)
1243-
+ }
1244-
+ issue3833: (_|_){
1245-
+ // [eval]
1246-
+ out: (_|_){
1247-
+ // [eval]
1248-
+ a: (_|_){
1249-
+ // [eval]
1250-
+ b: (_|_){
1251-
+ // [eval] issue3833.out.a.b: field not allowed:
1252-
+ // ./issue3833.cue:4:6
1253-
+ // ./issue3833.cue:10:3
1254-
+ }
1255-
c: (string){ "foo" }
1256-
}
1257-
}
1258-
@@ -541,38 +435,11 @@
1225+
}
1226+
issue3833: (struct){
1227+
out: (#struct){
1228+
@@ -541,38 +425,11 @@
12591229
#Main: (#struct){
12601230
namespace: (string){ string }
12611231
output: (_|_){
@@ -1296,7 +1266,7 @@ diff old new
12961266
let base#6 = (#struct){
12971267
someMsg: (string){ string }
12981268
obs: (#struct){ |(*(#struct){
1299-
@@ -615,6 +482,19 @@
1269+
@@ -615,6 +472,19 @@
13001270
}
13011271
}
13021272
}
@@ -1316,7 +1286,7 @@ diff old new
13161286
}
13171287
}
13181288
out: (#struct){
1319-
@@ -634,7 +514,9 @@
1289+
@@ -634,7 +504,9 @@
13201290
}
13211291
out: (#struct){
13221292
b1: (_|_){
@@ -1327,7 +1297,7 @@ diff old new
13271297
// disjunction.withErr.t1.out.b1: conflicting values null and {b2:{b3:params.mayExistLater}} (mismatched types null and struct):
13281298
// ./validators.cue:29:7
13291299
// ./validators.cue:31:17
1330-
@@ -644,17 +526,8 @@
1300+
@@ -644,17 +516,8 @@
13311301
// ./validators.cue:32:17
13321302
// disjunction.withErr.t1.out.b1.b2.b3: undefined field: mayExistLater:
13331303
// ./validators.cue:29:22
@@ -1349,7 +1319,6 @@ diff old new
13491319
}
13501320
-- diff/todo/p1 --
13511321
embed.openValidator.t1.err: unexpected pass.
1352-
issue3833.out.a.b: field should be alloweds
13531322
-- diff/todo/p2 --
13541323
and.transitive(WithEmbed)?.out.ok: unexpected error
13551324
-- out/eval --

0 commit comments

Comments
 (0)