this repo has no description
0
fork

Configure Feed

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

internal/core/export: always export required fields

Required fields are either printed (in case of a definition) or
erroneous (in case of export). We now always print them and
leave error reporting of required fields, if desired, up to the user.

Fixes #2305

Change-Id: Id440a20a5f4b247a52ce4c74555903df39c7214f
Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/552169
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+52 -10
+42
internal/core/export/testdata/main/def.txtar
··· 6 6 #d: { 7 7 e!: string 8 8 e?: =~"a" 9 + 10 + f?: 1 9 11 } 12 + 13 + // Issue #2305 14 + g: #d 10 15 -- out/definition -- 11 16 a: int | *2 12 17 b?: 4 | 5 ··· 15 20 } 16 21 #d: { 17 22 e!: =~"a" 23 + f?: 1 18 24 } 25 + 26 + // Issue #2305 27 + g: #d 19 28 -- out/doc -- 20 29 [] 21 30 [a] ··· 23 32 [c] 24 33 [#d] 25 34 [#d e] 35 + [#d f] 36 + [g] 37 + - Issue #2305 38 + 39 + [g e] 40 + [g f] 26 41 -- out/value -- 27 42 == Simplified 28 43 { 29 44 a: *2 | int 30 45 c: {} 46 + 47 + // Issue #2305 48 + g: { 49 + e!: =~"a" 50 + } 31 51 } 32 52 == Raw 33 53 { ··· 36 56 c: {} 37 57 #d: { 38 58 e!: =~"a" 59 + f?: 1 60 + } 61 + 62 + // Issue #2305 63 + g: { 64 + e!: =~"a" 65 + f?: 1 39 66 } 40 67 } 41 68 == Final 42 69 { 43 70 a: 2 44 71 c: {} 72 + g: { 73 + e!: =~"a" 74 + } 45 75 } 46 76 == All 47 77 { ··· 50 80 c: {} 51 81 #d: { 52 82 e!: =~"a" 83 + f?: 1 84 + } 85 + 86 + // Issue #2305 87 + g: { 88 + e!: =~"a" 89 + f?: 1 53 90 } 54 91 } 55 92 == Eval ··· 59 96 c: {} 60 97 #d: { 61 98 e!: =~"a" 99 + f?: 1 100 + } 101 + g: { 102 + e!: =~"a" 103 + f?: 1 62 104 } 63 105 }
+10 -10
internal/core/export/value.go
··· 74 74 75 75 case *adt.Bottom: 76 76 switch { 77 - case n.IsConstraint(): 78 - // Constraints may always be the original value. 79 - // TODO: this was included for backwards compatibility. But 80 - // should we show the error here? It signifies that this field 81 - // may not be used. 77 + case n.ArcType == adt.ArcOptional: 78 + // Optional fields may always be the original value. 79 + 82 80 case e.cfg.ShowErrors && x.ChildError: 83 81 // TODO(perf): use precompiled arc statistics 84 82 if len(n.Arcs) > 0 && n.Arcs[0].Label.IsInt() && !e.showArcs(n) && attrs == nil { ··· 438 436 continue 439 437 } 440 438 441 - if isOptional := arc.IsConstraint(); isOptional { 442 - if !p.ShowOptional { 443 - continue 444 - } 445 - internal.SetConstraint(f, arc.ArcType.Token()) 439 + if arc.ArcType == adt.ArcOptional && !p.ShowOptional { 440 + continue 446 441 } 442 + // TODO: report an error for required fields in Final mode? 443 + // This package typically does not create errors that did not result 444 + // from evaluation already. 445 + 446 + internal.SetConstraint(f, arc.ArcType.Token()) 447 447 448 448 f.Value = e.vertex(arc) 449 449