Skip to content

Commit fbcadd9

Browse files
committed
internal/core/adt: limit error propagation to cross package
This check mostly necessary to catch cross-package errors. Within packages it may result in unintuitive error messages. This is because the error status of a node may change during evaluation. Note that package nodes are self-contained and that because of a lack of cycles, a package node is always fully evaluated before a referring node. In order to determine whether an error crosses package boundaries, we mark the originating node in the error. An error orginates from a different package if they root node is different. There are probably less error-prone mechanisms to determine the package, but the impact of getting it wrong is quite small, so this is sufficient for now. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I82c5e199a1bc0746abb60b825c31e03587061f39 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200793 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Matthew Sackman <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent abb6364 commit fbcadd9

20 files changed

+141
-128
lines changed

cue/testdata/comprehensions/iferror.txtar

+3-10
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ Result:
190190
incomplete: (_|_){
191191
// [incomplete] incomplete: undefined field: d:
192192
// ./in.cue:16:7
193+
// incomplete: undefined field: d:
194+
// ./in.cue:23:21
193195
list: (#list){
194196
0: (int){ 1 }
195197
1: (int){ 2 }
@@ -268,16 +270,7 @@ diff old new
268270

269271
Result:
270272
(_|_){
271-
@@ -31,8 +31,6 @@
272-
incomplete: (_|_){
273-
// [incomplete] incomplete: undefined field: d:
274-
// ./in.cue:16:7
275-
- // incomplete: undefined field: d:
276-
- // ./in.cue:23:21
277-
list: (#list){
278-
0: (int){ 1 }
279-
1: (int){ 2 }
280-
@@ -66,17 +64,23 @@
273+
@@ -66,17 +66,23 @@
281274
issue1972: (_|_){
282275
// [eval]
283276
err1: (_|_){

cue/testdata/cycle/023_reentrance.txtar

+8-18
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,19 @@ Result:
8787
// ./in.cue:7:5
8888
// ./in.cue:3:35
8989
// ./in.cue:5:5
90+
// non-concrete value int in operand to <:
91+
// ./in.cue:10:5
92+
// ./in.cue:3:35
93+
// ./in.cue:5:5
9094
}
9195
}
9296
fib: (_|_){
9397
// [incomplete] fib: non-concrete value int in operand to >=:
9498
// ./in.cue:7:5
9599
// ./in.cue:5:5
100+
// fib: non-concrete value int in operand to <:
101+
// ./in.cue:10:5
102+
// ./in.cue:5:5
96103
n: (int){ int }
97104
}
98105
fib1: (int){ 1 }
@@ -150,24 +157,7 @@ diff old new
150157

151158
Result:
152159
(_|_){
153-
@@ -16,10 +12,6 @@
154-
// ./in.cue:7:5
155-
// ./in.cue:3:35
156-
// ./in.cue:5:5
157-
- // non-concrete value int in operand to <:
158-
- // ./in.cue:10:5
159-
- // ./in.cue:3:35
160-
- // ./in.cue:5:5
161-
}
162-
}
163-
fib: (_|_){
164-
@@ -26,33 +18,23 @@
165-
// [incomplete] fib: non-concrete value int in operand to >=:
166-
// ./in.cue:7:5
167-
// ./in.cue:5:5
168-
- // fib: non-concrete value int in operand to <:
169-
- // ./in.cue:10:5
170-
- // ./in.cue:5:5
160+
@@ -32,27 +28,20 @@
171161
n: (int){ int }
172162
}
173163
fib1: (int){ 1 }

cue/testdata/cycle/chain.txtar

+14-14
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ issue2052: full: {
208208
d: #Depth & {#in: tree}
209209
}
210210
-- out/evalalpha/stats --
211-
Leaks: 19999
212-
Freed: 1462
213-
Reused: 1461
214-
Allocs: 20000
211+
Leaks: 20362
212+
Freed: 1534
213+
Reused: 1533
214+
Allocs: 20363
215215
Retain: 0
216216

217-
Unifications: 7506
218-
Conjuncts: 107540
219-
Disjuncts: 13655
217+
Unifications: 7655
218+
Conjuncts: 109511
219+
Disjuncts: 13941
220220
-- out/evalalpha --
221221
Errors:
222222
issue2052.t1.#Depth: adding field #basic not allowed as field set was already referenced:
@@ -725,18 +725,18 @@ diff old new
725725
-Reused: 1816
726726
-Allocs: 70
727727
-Retain: 169
728-
+Leaks: 19999
729-
+Freed: 1462
730-
+Reused: 1461
731-
+Allocs: 20000
728+
+Leaks: 20362
729+
+Freed: 1534
730+
+Reused: 1533
731+
+Allocs: 20363
732732
+Retain: 0
733733

734734
-Unifications: 801
735735
-Conjuncts: 3177
736736
-Disjuncts: 1979
737-
+Unifications: 7506
738-
+Conjuncts: 107540
739-
+Disjuncts: 13655
737+
+Unifications: 7655
738+
+Conjuncts: 109511
739+
+Disjuncts: 13941
740740
-- diff/-out/evalalpha<==>+out/eval --
741741
diff old new
742742
--- old

cue/testdata/cycle/compbottomnofinal.txtar

+6-42
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,6 @@ Disjuncts: 215
384384
#Y: (_|_){
385385
// [incomplete] small.p1.#Y: undefined field: port:
386386
// ./in.cue:28:50
387-
// small.p1.#X.port: cyclic reference to field port:
388-
// ./in.cue:31:4
389387
}
390388
#X: (_|_){
391389
// [incomplete] small.p1.#X.port: cyclic reference to field port:
@@ -409,8 +407,6 @@ Disjuncts: 215
409407
#Y: (_|_){
410408
// [incomplete] medium.p1.#Y: undefined field: port:
411409
// ./in.cue:58:50
412-
// medium.p1.#X.port: cyclic reference to field port:
413-
// ./in.cue:70:4
414410
}
415411
Y: (struct){
416412
}
@@ -423,8 +419,6 @@ Disjuncts: 215
423419
#Y: (_|_){
424420
// [incomplete] medium.p2.#Y: undefined field: port:
425421
// ./in.cue:80:50
426-
// medium.p2.#X.port: cyclic reference to field port:
427-
// ./in.cue:86:4
428422
}
429423
#X: (_|_){
430424
// [incomplete] medium.p2.#X.port: cyclic reference to field port:
@@ -439,8 +433,6 @@ Disjuncts: 215
439433
#Y: (_|_){
440434
// [incomplete] medium.p3.#Y: undefined field: port:
441435
// ./in.cue:108:50
442-
// medium.p3.#X.port: cyclic reference to field port:
443-
// ./in.cue:114:4
444436
}
445437
#X: (_|_){
446438
// [incomplete] medium.p3.#X.port: cyclic reference to field port:
@@ -455,9 +447,7 @@ Disjuncts: 215
455447
// ./in.cue:134:4
456448
}
457449
#Y: (_|_){
458-
// [incomplete] medium.p4.#X.port: cyclic reference to field port:
459-
// ./in.cue:134:4
460-
// medium.p4.#Y: undefined field: port:
450+
// [incomplete] medium.p4.#Y: undefined field: port:
461451
// ./in.cue:142:50
462452
}
463453
}
@@ -496,8 +486,6 @@ Disjuncts: 215
496486
X: (_|_){
497487
// [incomplete] large.p1.X: undefined field: port:
498488
// ./in.cue:199:33
499-
// large.p1.#X.port: cyclic reference to field port:
500-
// ./in.cue:211:4
501489
}
502490
#X: (_|_){
503491
// [incomplete] large.p1.#X.port: cyclic reference to field port:
@@ -514,8 +502,6 @@ Disjuncts: 215
514502
X: (_|_){
515503
// [incomplete] large.p2.X: undefined field: port:
516504
// ./in.cue:235:33
517-
// large.p2.#X.port: cyclic reference to field port:
518-
// ./in.cue:252:4
519505
}
520506
Y: (struct){
521507
userinfo: (string){ "user" }
@@ -536,8 +522,6 @@ Disjuncts: 215
536522
X: (_|_){
537523
// [incomplete] large.p3.X: undefined field: port:
538524
// ./in.cue:276:33
539-
// large.p3.#X.port: cyclic reference to field port:
540-
// ./in.cue:288:4
541525
}
542526
#X: (_|_){
543527
// [incomplete] large.p3.#X.port: cyclic reference to field port:
@@ -558,8 +542,6 @@ Disjuncts: 215
558542
X: (_|_){
559543
// [incomplete] large.p4.X: undefined field: port:
560544
// ./in.cue:317:33
561-
// large.p4.#X.port: cyclic reference to field port:
562-
// ./in.cue:329:4
563545
}
564546
#X: (_|_){
565547
// [incomplete] large.p4.#X.port: cyclic reference to field port:
@@ -582,7 +564,7 @@ Disjuncts: 215
582564
diff old new
583565
--- old
584566
+++ new
585-
@@ -1,35 +1,36 @@
567+
@@ -1,35 +1,34 @@
586568
(struct){
587569
minimal: (struct){
588570
a: (_|_){
@@ -622,8 +604,6 @@ diff old new
622604
+ #Y: (_|_){
623605
+ // [incomplete] small.p1.#Y: undefined field: port:
624606
+ // ./in.cue:28:50
625-
+ // small.p1.#X.port: cyclic reference to field port:
626-
+ // ./in.cue:31:4
627607
+ }
628608
+ #X: (_|_){
629609
+ // [incomplete] small.p1.#X.port: cyclic reference to field port:
@@ -641,7 +621,7 @@ diff old new
641621
}
642622
}
643623
}
644-
@@ -36,65 +37,69 @@
624+
@@ -36,65 +35,61 @@
645625
medium: (struct){
646626
#userHostPort: (string){ "^(:(?P<port>\\d+))?$" }
647627
p1: (struct){
@@ -675,8 +655,6 @@ diff old new
675655
+ #Y: (_|_){
676656
+ // [incomplete] medium.p1.#Y: undefined field: port:
677657
+ // ./in.cue:58:50
678-
+ // medium.p1.#X.port: cyclic reference to field port:
679-
+ // ./in.cue:70:4
680658
+ }
681659
+ Y: (struct){
682660
+ }
@@ -689,8 +667,6 @@ diff old new
689667
+ #Y: (_|_){
690668
+ // [incomplete] medium.p2.#Y: undefined field: port:
691669
+ // ./in.cue:80:50
692-
+ // medium.p2.#X.port: cyclic reference to field port:
693-
+ // ./in.cue:86:4
694670
+ }
695671
+ #X: (_|_){
696672
+ // [incomplete] medium.p2.#X.port: cyclic reference to field port:
@@ -724,8 +700,6 @@ diff old new
724700
- // [cycle] medium.p4.#X: cycle with field Y.port:
725701
- // ./in.cue:134:7
726702
+ // ./in.cue:108:50
727-
+ // medium.p3.#X.port: cyclic reference to field port:
728-
+ // ./in.cue:114:4
729703
+ }
730704
+ #X: (_|_){
731705
+ // [incomplete] medium.p3.#X.port: cyclic reference to field port:
@@ -740,9 +714,7 @@ diff old new
740714
+ // ./in.cue:134:4
741715
+ }
742716
+ #Y: (_|_){
743-
+ // [incomplete] medium.p4.#X.port: cyclic reference to field port:
744-
+ // ./in.cue:134:4
745-
+ // medium.p4.#Y: undefined field: port:
717+
+ // [incomplete] medium.p4.#Y: undefined field: port:
746718
+ // ./in.cue:142:50
747719
}
748720
}
@@ -763,7 +735,7 @@ diff old new
763735
}
764736
Y: (struct){
765737
}
766-
@@ -101,14 +106,14 @@
738+
@@ -101,14 +96,14 @@
767739
}
768740
p6: (struct){
769741
#X: (_|_){
@@ -786,7 +758,7 @@ diff old new
786758
}
787759
}
788760
}
789-
@@ -115,81 +120,91 @@
761+
@@ -115,81 +110,83 @@
790762
large: (struct){
791763
#userHostPort: (string){ "^((?P<userinfo>[[:alnum:]]*)@)?(?P<host>[[:alnum:].]+)(:(?P<port>\\d+))?$" }
792764
p1: (struct){
@@ -872,8 +844,6 @@ diff old new
872844
+ X: (_|_){
873845
+ // [incomplete] large.p1.X: undefined field: port:
874846
+ // ./in.cue:199:33
875-
+ // large.p1.#X.port: cyclic reference to field port:
876-
+ // ./in.cue:211:4
877847
+ }
878848
+ #X: (_|_){
879849
+ // [incomplete] large.p1.#X.port: cyclic reference to field port:
@@ -890,8 +860,6 @@ diff old new
890860
+ X: (_|_){
891861
+ // [incomplete] large.p2.X: undefined field: port:
892862
+ // ./in.cue:235:33
893-
+ // large.p2.#X.port: cyclic reference to field port:
894-
+ // ./in.cue:252:4
895863
+ }
896864
+ Y: (struct){
897865
+ userinfo: (string){ "user" }
@@ -912,8 +880,6 @@ diff old new
912880
+ X: (_|_){
913881
+ // [incomplete] large.p3.X: undefined field: port:
914882
+ // ./in.cue:276:33
915-
+ // large.p3.#X.port: cyclic reference to field port:
916-
+ // ./in.cue:288:4
917883
+ }
918884
+ #X: (_|_){
919885
+ // [incomplete] large.p3.#X.port: cyclic reference to field port:
@@ -934,8 +900,6 @@ diff old new
934900
+ X: (_|_){
935901
+ // [incomplete] large.p4.X: undefined field: port:
936902
+ // ./in.cue:317:33
937-
+ // large.p4.#X.port: cyclic reference to field port:
938-
+ // ./in.cue:329:4
939903
+ }
940904
+ #X: (_|_){
941905
+ // [incomplete] large.p4.#X.port: cyclic reference to field port:

cue/testdata/eval/issue2550.txtar

+10-19
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,29 @@ Result:
4141
let _bar#1 = (_){ _ }
4242
}
4343
-- out/evalalpha --
44+
Errors:
45+
undefined field: missing:
46+
./in.cue:4:8
47+
48+
Result:
4449
(_|_){
45-
// [incomplete] undefined field: missing:
50+
// [eval] undefined field: missing:
4651
// ./in.cue:4:8
4752
foo: (_|_){
4853
// [incomplete] undefined field: missing:
4954
// ./in.cue:4:8
5055
}
5156
bar: (#struct){
5257
}
53-
let _bar#1 = (_|_){
54-
// [incomplete] undefined field: missing:
55-
// ./in.cue:4:8
56-
}
58+
let _bar#1 = (_){ _ }
5759
}
5860
-- diff/-out/evalalpha<==>+out/eval --
5961
diff old new
6062
--- old
6163
+++ new
62-
@@ -1,13 +1,14 @@
63-
-Errors:
64-
-undefined field: missing:
65-
- ./in.cue:4:8
66-
-
67-
-Result:
64+
@@ -6,7 +6,10 @@
6865
(_|_){
69-
- // [eval] undefined field: missing:
70-
+ // [incomplete] undefined field: missing:
66+
// [eval] undefined field: missing:
7167
// ./in.cue:4:8
7268
- foo: (string){ string }
7369
+ foo: (_|_){
@@ -76,11 +72,6 @@ diff old new
7672
+ }
7773
bar: (#struct){
7874
}
79-
- let _bar#1 = (_){ _ }
80-
+ let _bar#1 = (_|_){
81-
+ // [incomplete] undefined field: missing:
82-
+ // ./in.cue:4:8
83-
+ }
84-
}
75+
let _bar#1 = (_){ _ }
8576
-- diff/todo/p2 --
8677
Let seems to have misplaced error, even though it does not affect outcome.

internal/core/adt/binop.go

+2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ func BinOp(c *OpContext, op Op, left, right Value) Value {
3232
return &Bottom{
3333
Code: IncompleteError,
3434
Err: c.Newf(msg, left, op),
35+
Node: c.vertex,
3536
}
3637
}
3738
if right.Concreteness() > Concrete {
3839
return &Bottom{
3940
Code: IncompleteError,
4041
Err: c.Newf(msg, right, op),
42+
Node: c.vertex,
4143
}
4244
}
4345

0 commit comments

Comments
 (0)