Skip to content

Commit 0c5769b

Browse files
mpvlmvdan
authored andcommitted
internal/core/adt: fix initArcs for errors in optional fields
An error in an optional field is okay. Yet, initArcs, which pre-initialized the arcs of the previously existing structure, would consider it to be erroneous. This would result in disjunction processing to be skipped. However, there was no actual error. This, in turn, would cause typo checking to be triggered, which result in missing fields, as some of the "evidence" for allowing a field was now missing. Fixes #4022 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I6f6c21f7eab1fa8117e27bd143f5eb32f00248b5 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1220129 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1220255
1 parent 46cf125 commit 0c5769b

File tree

2 files changed

+21
-123
lines changed

2 files changed

+21
-123
lines changed

cue/testdata/disjunctions/errors.txtar

Lines changed: 18 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,6 @@ MisalignedConjunct: 1
166166
NumCloseIDs: 11
167167
-- out/evalalpha --
168168
Errors:
169-
issue4022.full.out.apiVersion: field not allowed:
170-
./optionalerror.cue:24:3
171-
issue4022.full.out.metadata: field not allowed:
172-
./optionalerror.cue:10:3
173-
./optionalerror.cue:23:3
174-
issue4022.reduced.out.metadata: field not allowed:
175-
./optionalerror.cue:2:18
176-
./optionalerror.cue:6:7
177169
issue516.x: 2 errors in empty disjunction:
178170
issue516.x.match: field not allowed:
179171
./in.cue:23:5
@@ -379,10 +371,8 @@ Result:
379371
}
380372
}) }
381373
}
382-
issue4022: (_|_){
383-
// [eval]
384-
reduced: (_|_){
385-
// [eval]
374+
issue4022: (struct){
375+
reduced: (struct){
386376
#NonNamespaced: (#struct){
387377
metadata: (#struct){
388378
namespace?: (_|_){
@@ -399,21 +389,16 @@ Result:
399389
}
400390
}
401391
}) }
402-
out: (_|_){
403-
// [eval]
404-
metadata: (_|_){
405-
// [eval] issue4022.reduced.out.metadata: field not allowed:
406-
// ./optionalerror.cue:2:18
407-
// ./optionalerror.cue:6:7
392+
out: (#struct){
393+
metadata: (#struct){
408394
namespace?: (_|_){
409395
// [user] explicit error (_|_ literal) in source:
410396
// ./optionalerror.cue:2:40
411397
}
412398
}
413399
}
414400
}
415-
full: (_|_){
416-
// [eval]
401+
full: (struct){
417402
#NonNamespaced: (#struct){
418403
metadata: (#struct){
419404
name!: (string){ string }
@@ -432,22 +417,15 @@ Result:
432417
}
433418
}
434419
}) }
435-
out: (_|_){
436-
// [eval]
437-
metadata: (_|_){
438-
// [eval] issue4022.full.out.metadata: field not allowed:
439-
// ./optionalerror.cue:10:3
440-
// ./optionalerror.cue:23:3
420+
out: (#struct){
421+
metadata: (#struct){
441422
name: (string){ "foo" }
442423
namespace?: (_|_){
443424
// [user] explicit error (_|_ literal) in source:
444425
// ./optionalerror.cue:12:16
445426
}
446427
}
447-
apiVersion: (_|_){
448-
// [eval] issue4022.full.out.apiVersion: field not allowed:
449-
// ./optionalerror.cue:24:3
450-
}
428+
apiVersion: (string){ "v1" }
451429
}
452430
}
453431
}
@@ -456,16 +434,8 @@ Result:
456434
diff old new
457435
--- old
458436
+++ new
459-
@@ -1,15 +1,18 @@
437+
@@ -1,15 +1,10 @@
460438
Errors:
461-
+issue4022.full.out.apiVersion: field not allowed:
462-
+ ./optionalerror.cue:24:3
463-
+issue4022.full.out.metadata: field not allowed:
464-
+ ./optionalerror.cue:10:3
465-
+ ./optionalerror.cue:23:3
466-
+issue4022.reduced.out.metadata: field not allowed:
467-
+ ./optionalerror.cue:2:18
468-
+ ./optionalerror.cue:6:7
469439
issue516.x: 2 errors in empty disjunction:
470440
issue516.x.match: field not allowed:
471441
- ./in.cue:20:6
@@ -480,7 +450,7 @@ diff old new
480450
./in.cue:3:19
481451
./in.cue:12:12
482452

483-
@@ -19,17 +22,12 @@
453+
@@ -19,17 +14,12 @@
484454
issue570: (_|_){
485455
// [eval]
486456
results: (_|_){
@@ -499,7 +469,7 @@ diff old new
499469
}
500470
#Output: (#struct){ |((#struct){
501471
result: (_){ _ }
502-
@@ -40,7 +38,9 @@
472+
@@ -40,7 +30,9 @@
503473
result: (list){
504474
}
505475
}, (#struct){
@@ -510,7 +480,7 @@ diff old new
510480
}
511481
error: (string){ string }
512482
}) }
513-
@@ -59,18 +59,10 @@
483+
@@ -59,18 +51,10 @@
514484
x: (_|_){
515485
// [eval] issue516.x: 2 errors in empty disjunction:
516486
// issue516.x.match: field not allowed:
@@ -530,7 +500,7 @@ diff old new
530500
metrics: (struct){
531501
foo: (struct){
532502
}
533-
@@ -136,13 +128,11 @@
503+
@@ -136,13 +120,11 @@
534504
reduced: (struct){
535505
list: (_|_){
536506
// [incomplete] issue3581.reduced.list: 2 errors in empty disjunction:
@@ -547,116 +517,46 @@ diff old new
547517
}
548518
c: (_){ _ }
549519
}
550-
@@ -186,7 +176,6 @@
520+
@@ -186,7 +168,6 @@
551521
p1: (struct){ |((struct){
552522
a?: (_|_){
553523
// [eval] issue3599.reduced.p1.a: conflicting values 2 and 1:
554524
- // ./issue3599.cue:32:2
555525
// ./issue3599.cue:32:9
556526
// ./issue3599.cue:32:11
557527
}
558-
@@ -194,7 +183,6 @@
528+
@@ -194,7 +175,6 @@
559529
a: (string){ string }
560530
b?: (_|_){
561531
// [eval] issue3599.reduced.p1.b: conflicting values 2 and 1:
562532
- // ./issue3599.cue:32:2
563533
// ./issue3599.cue:32:35
564534
// ./issue3599.cue:32:37
565535
}
566-
@@ -202,7 +190,6 @@
536+
@@ -202,7 +182,6 @@
567537
p2: (struct){ |((struct){
568538
a?: (_|_){
569539
// [eval] issue3599.reduced.p2.a: conflicting values 2 and 1:
570540
- // ./issue3599.cue:37:2
571541
// ./issue3599.cue:37:9
572542
// ./issue3599.cue:37:11
573543
}
574-
@@ -210,7 +197,6 @@
544+
@@ -210,7 +189,6 @@
575545
a: (string){ string }
576546
b?: (_|_){
577547
// [eval] issue3599.reduced.p2.b: conflicting values 2 and 1:
578548
- // ./issue3599.cue:37:2
579549
// ./issue3599.cue:37:35
580550
// ./issue3599.cue:37:37
581551
}
582-
@@ -221,14 +207,15 @@
552+
@@ -221,7 +199,6 @@
583553
a: (int){ 1 }
584554
let B#1 = (_|_){
585555
// [eval] issue3599.let.B: conflicting values 2 and 1:
586556
- // ./issue3599.cue:40:2
587557
// ./issue3599.cue:40:29
588558
// ./issue3599.cue:40:31
589559
}
590-
}) }
591-
}
592-
- issue4022: (struct){
593-
- reduced: (struct){
594-
+ issue4022: (_|_){
595-
+ // [eval]
596-
+ reduced: (_|_){
597-
+ // [eval]
598-
#NonNamespaced: (#struct){
599-
metadata: (#struct){
600-
namespace?: (_|_){
601-
@@ -245,16 +232,21 @@
602-
}
603-
}
604-
}) }
605-
- out: (#struct){
606-
- metadata: (#struct){
607-
- namespace?: (_|_){
608-
- // [user] explicit error (_|_ literal) in source:
609-
- // ./optionalerror.cue:2:40
610-
- }
611-
- }
612-
- }
613-
- }
614-
- full: (struct){
615-
+ out: (_|_){
616-
+ // [eval]
617-
+ metadata: (_|_){
618-
+ // [eval] issue4022.reduced.out.metadata: field not allowed:
619-
+ // ./optionalerror.cue:2:18
620-
+ // ./optionalerror.cue:6:7
621-
+ namespace?: (_|_){
622-
+ // [user] explicit error (_|_ literal) in source:
623-
+ // ./optionalerror.cue:2:40
624-
+ }
625-
+ }
626-
+ }
627-
+ }
628-
+ full: (_|_){
629-
+ // [eval]
630-
#NonNamespaced: (#struct){
631-
metadata: (#struct){
632-
name!: (string){ string }
633-
@@ -273,8 +265,12 @@
634-
}
635-
}
636-
}) }
637-
- out: (#struct){
638-
- metadata: (#struct){
639-
+ out: (_|_){
640-
+ // [eval]
641-
+ metadata: (_|_){
642-
+ // [eval] issue4022.full.out.metadata: field not allowed:
643-
+ // ./optionalerror.cue:10:3
644-
+ // ./optionalerror.cue:23:3
645-
name: (string){ "foo" }
646-
namespace?: (_|_){
647-
// [user] explicit error (_|_ literal) in source:
648-
@@ -281,7 +277,10 @@
649-
// ./optionalerror.cue:12:16
650-
}
651-
}
652-
- apiVersion: (string){ "v1" }
653-
+ apiVersion: (_|_){
654-
+ // [eval] issue4022.full.out.apiVersion: field not allowed:
655-
+ // ./optionalerror.cue:24:3
656-
+ }
657-
}
658-
}
659-
}
660560
-- diff/todo/p3 --
661561
Missing error positions.
662562
-- diff/explanation --

internal/core/adt/disjunct2.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,17 @@ func (n *nodeContext) scheduleDisjunction(d envDisjunct) {
216216
}
217217

218218
func initArcs(ctx *OpContext, v *Vertex) bool {
219-
ok := true
220219
for _, a := range v.Arcs {
221220
s := a.getState(ctx)
222221
if s != nil && s.errs != nil {
223-
ok = false
224222
if a.ArcType == ArcMember {
225-
break
223+
return false
226224
}
227225
} else if !initArcs(ctx, a) {
228-
ok = false
226+
return false
229227
}
230228
}
231-
return ok
229+
return true
232230
}
233231

234232
func (n *nodeContext) processDisjunctions() *Bottom {

0 commit comments

Comments
 (0)