this repo has no description
0
fork

Configure Feed

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

internal/core/adt: pass errors up in nested comprehensions

Change-Id: I97449f51f214f36d6bd7db0c69a8001e6c7393d6
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7941
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>

+116 -10
+94
cue/testdata/comprehensions/iferror.txtar
··· 1 + -- in.cue -- 2 + a: { b: 2, c: int } 3 + 4 + wrongConcreteType: { 5 + if a.b { 6 + 2 7 + } 8 + } 9 + 10 + wrongType: { 11 + if a.c { 12 + 2 13 + } 14 + } 15 + 16 + incomplete: { 17 + if a.d { 18 + 2 19 + } 20 + } 21 + 22 + incomplete: { 23 + list: [1, 2, 3] 24 + for x in list if a.d { 25 + x 26 + } 27 + } 28 + -- out/compile -- 29 + --- in.cue 30 + { 31 + a: { 32 + b: 2 33 + c: int 34 + } 35 + wrongConcreteType: { 36 + if 〈1;a〉.b { 37 + 2 38 + } 39 + } 40 + wrongType: { 41 + if 〈1;a〉.c { 42 + 2 43 + } 44 + } 45 + incomplete: { 46 + if 〈1;a〉.d { 47 + 2 48 + } 49 + } 50 + incomplete: { 51 + list: [ 52 + 1, 53 + 2, 54 + 3, 55 + ] 56 + for _, x in 〈0;list〉 if 〈2;a〉.d { 57 + 〈1;x〉 58 + } 59 + } 60 + } 61 + -- out/eval -- 62 + Errors: 63 + wrongConcreteType: cannot use 2 (type int) as type bool: 64 + ./in.cue:4:2 65 + wrongType: cannot use int (type int) as type bool: 66 + ./in.cue:10:2 67 + 68 + Result: 69 + (_|_){ 70 + // [eval] 71 + a: (struct){ 72 + b: (int){ 2 } 73 + c: (int){ int } 74 + } 75 + wrongConcreteType: (_|_){ 76 + // [eval] wrongConcreteType: cannot use 2 (type int) as type bool: 77 + // ./in.cue:4:2 78 + } 79 + wrongType: (_|_){ 80 + // [eval] wrongType: cannot use int (type int) as type bool: 81 + // ./in.cue:10:2 82 + } 83 + incomplete: (_|_){ 84 + // [incomplete] incomplete: undefined field d: 85 + // ./in.cue:16:7 86 + // incomplete: undefined field d: 87 + // ./in.cue:23:21 88 + list: (#list){ 89 + 0: (int){ 1 } 90 + 1: (int){ 2 } 91 + 2: (int){ 3 } 92 + } 93 + } 94 + }
+5 -3
cue/testdata/cycle/comprehension.txtar
··· 12 12 } 13 13 } 14 14 15 - // TODO(errors): this should result in an incomplete error. 16 - // A simplified control flow should help here. 15 + // This should result in an incomplete error (a reference cycle error classifies 16 + // as incomplete). 17 17 B: { 18 18 a: { 19 19 parent: "" ··· 64 64 B: (struct){ 65 65 a: (struct){ 66 66 parent: (string){ "" } 67 - children: (#list){ 67 + children: (_|_){ 68 + // [cycle] cycle error: 69 + // ./in.cue:19:47 68 70 } 69 71 } 70 72 }
+3 -5
internal/core/adt/context.go
··· 187 187 return c.src.Pos() 188 188 } 189 189 190 - func (c *OpContext) spawn(node *Vertex) *OpContext { 191 - sub := *c 192 - node.Parent = c.e.Vertex 193 - sub.e = &Environment{ 190 + func (c *OpContext) spawn(node *Vertex) *Environment { 191 + node.Parent = c.e.Vertex // TODO: Is this necessary? 192 + return &Environment{ 194 193 Up: c.e, 195 194 Vertex: node, 196 195 ··· 199 198 Deref: c.e.Deref, 200 199 Cycles: c.e.Cycles, 201 200 } 202 - return &sub 203 201 } 204 202 205 203 func (c *OpContext) Env(upCount int32) *Environment {
+14 -2
internal/core/adt/expr.go
··· 1251 1251 n.Arcs = append(n.Arcs, v) 1252 1252 } 1253 1253 1254 - x.Dst.yield(c.spawn(n), f) 1254 + sub := c.spawn(n) 1255 + saved := c.PushState(sub, x.Dst.Source()) 1256 + x.Dst.yield(c, f) 1257 + if b := c.PopState(saved); b != nil { 1258 + c.AddBottom(b) 1259 + break 1260 + } 1255 1261 if c.HasErr() { 1256 1262 break 1257 1263 } ··· 1304 1310 n := &Vertex{Arcs: []*Vertex{ 1305 1311 {Label: x.Label, Conjuncts: []Conjunct{{c.Env(0), x.Expr, 0}}}, 1306 1312 }} 1307 - x.Dst.yield(c.spawn(n), f) 1313 + 1314 + sub := c.spawn(n) 1315 + saved := c.PushState(sub, x.Dst.Source()) 1316 + x.Dst.yield(c, f) 1317 + if b := c.PopState(saved); b != nil { 1318 + c.AddBottom(b) 1319 + } 1308 1320 } 1309 1321 1310 1322 // A ValueClause represents the value part of a comprehension.