this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

core/adt: identify duplicate errors when pairwise-combining

Revert cue/errors/errors.go to before
https://review.gerrithub.io/c/cue-lang/cue/+/1199401

The previous attempt to fix this issue was extremely fragile: it only
worked if there was an attempt to append the exact same error
contiguously. In practice we have seen that this may not happen,
rendering that fix ineffective. So it is reverted here.

By contrast, in core/adt *OpContext.node(), it can be the case that the
call to unifyNode returns the opContext's own errors. The subsequent
call to *OpContext.AddBottom() and CombineErrors() can therefore result
in the duplication of the opContext's errors. Identifying and solving
this in CombineErrors() seems to be a robust solution.

Fixes #3307

Signed-off-by: Matthew Sackman <matthew@cue.works>
Change-Id: Ib3a0bff023343d410273017ea24e92d54346d77c
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199723
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>

+98 -24
+4 -12
cue/errors/errors.go
··· 274 274 275 275 // Append combines two errors, flattening Lists as necessary. 276 276 func Append(a, b Error) Error { 277 - switch a := a.(type) { 277 + switch x := a.(type) { 278 278 case nil: 279 279 return b 280 280 case list: 281 - return appendToList(a, b) 282 - } 283 - switch b := b.(type) { 284 - case nil: 285 - return a 286 - case list: 287 - return appendToList(list{a}, b) 288 - } 289 - if a == b { 290 - return a 281 + return appendToList(x, b) 291 282 } 292 - return list{a, b} 283 + // Preserve order of errors. 284 + return appendToList(list{a}, b) 293 285 } 294 286 295 287 // Errors reports the individual errors associated with an error, which is
+14 -9
internal/core/adt/errors.go
··· 176 176 a, _ := Unwrap(x).(*Bottom) 177 177 b, _ := Unwrap(y).(*Bottom) 178 178 179 - if a == b && isCyclePlaceholder(a) { 180 - return a 181 - } 182 179 switch { 183 - case a != nil && b != nil: 184 - case a != nil: 180 + case a == nil && b == nil: 181 + return nil 182 + case a == nil: 183 + return b 184 + case b == nil: 185 + return a 186 + case a == b && isCyclePlaceholder(a): 185 187 return a 186 - case b != nil: 187 - return b 188 - default: 189 - return nil 188 + case a == b: 189 + // Don't return a (or b) because they may have other non-nil fields. 190 + return &Bottom{ 191 + Src: src, 192 + Err: a.Err, 193 + Code: a.Code, 194 + } 190 195 } 191 196 192 197 if a.Code != b.Code {
+2 -2
internal/core/export/testdata/main/alias.txtar
··· 366 366 } 367 367 selfRefValue: { 368 368 struct: { 369 - a: _|_ // valueAlias.selfRefValue.struct.a: incomplete list: _ (and 3 more errors) 369 + a: _|_ // valueAlias.selfRefValue.struct.a: incomplete list: _ (and 1 more errors) 370 370 } 371 371 pattern: { 372 372 a: {} ··· 516 516 selfRefValue: { 517 517 struct: { 518 518 - a: _|_ // cycle error 519 - + a: _|_ // valueAlias.selfRefValue.struct.a: incomplete list: _ (and 3 more errors) 519 + + a: _|_ // valueAlias.selfRefValue.struct.a: incomplete list: _ (and 1 more errors) 520 520 } 521 521 pattern: { 522 522 a: {}
+78 -1
internal/core/export/testdata/main/simplify.txtar
··· 41 41 [additional confs] 42 42 -- diff/value/explanation -- 43 43 Benign change in error message. 44 + -- out/value-v3 -- 45 + == Simplified 46 + { 47 + x: { 48 + y: int64 49 + } 50 + s: strings.MinRunes(4) & strings.MaxRunes(7) 51 + additional: { 52 + env: _ 53 + confs: { 54 + if env {} 55 + } 56 + } 57 + } 58 + == Raw 59 + { 60 + x: { 61 + y: >=-9223372036854775808 & <=9223372036854775807 & int 62 + } 63 + s: strings.MinRunes(4) & strings.MaxRunes(7) 64 + additional: { 65 + env: _ 66 + confs: { 67 + if env {} 68 + } 69 + } 70 + } 71 + == Final 72 + { 73 + x: { 74 + y: int64 75 + } 76 + s: strings.MinRunes(4) & strings.MaxRunes(7) 77 + additional: { 78 + env: _ 79 + confs: _|_ // additional.confs: incomplete bool: _ 80 + } 81 + } 82 + == All 83 + { 84 + x: { 85 + y: int64 86 + } 87 + s: strings.MinRunes(4) & strings.MaxRunes(7) 88 + additional: { 89 + env: _ 90 + confs: { 91 + if env {} 92 + } 93 + } 94 + } 95 + == Eval 96 + { 97 + x: { 98 + y: >=-9223372036854775808 & <=9223372036854775807 & int 99 + } 100 + s: strings.MinRunes(4) & strings.MaxRunes(7) 101 + additional: { 102 + env: _ 103 + confs: { 104 + if env {} 105 + } 106 + } 107 + } 108 + -- diff/-out/value-v3<==>+out/value -- 109 + diff old new 110 + --- old 111 + +++ new 112 + @@ -32,7 +32,7 @@ 113 + s: strings.MinRunes(4) & strings.MaxRunes(7) 114 + additional: { 115 + env: _ 116 + - confs: _|_ // additional.confs: incomplete bool: _ (and 1 more errors) 117 + + confs: _|_ // additional.confs: incomplete bool: _ 118 + } 119 + } 120 + == All 44 121 -- out/value -- 45 122 == Simplified 46 123 { ··· 76 153 s: strings.MinRunes(4) & strings.MaxRunes(7) 77 154 additional: { 78 155 env: _ 79 - confs: _|_ // additional.confs: incomplete bool: _ 156 + confs: _|_ // additional.confs: incomplete bool: _ (and 1 more errors) 80 157 } 81 158 } 82 159 == All