this repo has no description
0
fork

Configure Feed

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

internal/core/adt: fix spurious error in ForClause.yield key binding

When iterating over a struct with an error (e.g., missing required field),
the OpContext would have an error set. The old code used Feature.ToValue
which called ctx.NewString/ctx.NewInt64, and these methods return the
context's error when c.HasErr() is true instead of creating the value.

This caused a spurious cascading error like "key value of dynamic field
must be concrete" even though the key label itself was valid - only the
iterated value had an error.

Fix this by constructing String and Num values directly, bypassing the
error-checking in NewString/NewInt64. The key is always derived from a
valid label, so it should not inherit unrelated errors from the context.

This resolves a todo/p2 in cue/testdata/comprehensions/fields.txtar.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I31c23a193ea67f22ae0c0b5bac14014494f9984a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1229649
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>

+8 -67
-66
cue/testdata/comprehensions/fields.txtar
··· 72 72 MisalignedConjunct: 3 73 73 74 74 NumCloseIDs: 5 75 - -- out/evalalpha -- 76 - (struct){ 77 - dynamic: (struct){ 78 - foo: (int){ 1 } 79 - foobar: (int){ 2 } 80 - } 81 - ignoreOptional: (struct){ 82 - #x: (#struct){ 83 - a?: (string){ string } 84 - b?: (string){ string } 85 - c: (string){ string } 86 - } 87 - y: (struct){ 88 - c: (string){ "exists" } 89 - } 90 - } 91 - missingRequiredError: (struct){ 92 - #x: (#struct){ 93 - a!: (string){ string } 94 - b?: (string){ string } 95 - c: (string){ string } 96 - } 97 - y: (_|_){ 98 - // [incomplete] missingRequiredError.y: missing required field in for comprehension: a: 99 - // ./in.cue:33:3 100 - // ./in.cue:27:3 101 - // ./in.cue:33:14 102 - // missingRequiredError.y: key value of dynamic field must be concrete, found _|_(missingRequiredError.y: missing required field in for comprehension: a): 103 - // ./in.cue:34:5 104 - } 105 - } 106 - issue560: (struct){ 107 - #User: (#struct){ 108 - tags_str: (string){ string } 109 - tags_map: (_|_){ 110 - // [incomplete] issue560.#User.tags_map: error in call to strings.Split: non-concrete value string: 111 - // ./in.cue:43:16 112 - // ./in.cue:41:13 113 - "{a}": (string){ string } 114 - } 115 - } 116 - user: (#struct){ 117 - tags_str: (string){ "b {c}" } 118 - tags_map: (#struct){ 119 - "{a}": (string){ string } 120 - b: (string){ string } 121 - "{c}": (string){ string } 122 - } 123 - } 124 - } 125 - } 126 - -- diff/-out/evalalpha<==>+out/eval -- 127 - diff old new 128 - --- old 129 - +++ new 130 - @@ -24,6 +24,8 @@ 131 - // ./in.cue:33:3 132 - // ./in.cue:27:3 133 - // ./in.cue:33:14 134 - + // missingRequiredError.y: key value of dynamic field must be concrete, found _|_(missingRequiredError.y: missing required field in for comprehension: a): 135 - + // ./in.cue:34:5 136 - } 137 - } 138 - issue560: (struct){ 139 - -- diff/todo/p2 -- 140 - Near-duplicate message 141 75 -- out/eval -- 142 76 (struct){ 143 77 dynamic: (struct){
+8 -1
internal/core/adt/expr.go
··· 2094 2094 IsDynamic: true, 2095 2095 anonymous: true, 2096 2096 } 2097 - key := a.Label.ToValue(c) 2097 + var key Value 2098 + if a.Label.IsString() { 2099 + key = &String{Src: c.src, Str: c.IndexToString(a.Label.safeIndex())} 2100 + } else { 2101 + num := &Num{Src: c.src, K: IntKind} 2102 + num.X.SetInt64(int64(a.Label.Index())) 2103 + key = num 2104 + } 2098 2105 v.AddConjunct(MakeRootConjunct(env, key)) 2099 2106 v.SetValue(c, key) 2100 2107 n.Arcs = append(n.Arcs, v)