Skip to content

Commit 5f12a04

Browse files
committed
internal/core/adt: more thorough evaluation for scalar values
This gives slightly less useful error messages in some cases, but at least it resolves in some cases where before it didn't. Fixes #3828 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I3c2db3f802055fb1290b8d714b8d6a81cb29551d Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211806 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 04fa872 commit 5f12a04

File tree

4 files changed

+16
-37
lines changed

4 files changed

+16
-37
lines changed

cue/testdata/eval/dynamic_field.txtar

+6-32
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ Result:
204204
issue3828: (struct){
205205
reduced: (struct){
206206
a: (struct){
207-
b: (_|_){
208-
// [incomplete] issue3828.reduced.a.b: key value of dynamic field must be concrete, found _|_(issue3828.reduced.a.b: cycle with field: x):
209-
// ./issue3828.cue:5:5
207+
b: (struct){
208+
foobot1: (bool){ true }
210209
}
211210
}
212211
str: (string){ "foobot1" }
@@ -219,9 +218,8 @@ Result:
219218
}
220219
}
221220
collaborators: (struct){
222-
repo1: (_|_){
223-
// [incomplete] issue3828.full.orgs.org1.collaborators.repo1: key value of dynamic field must be concrete, found _|_(issue3828.full.orgs.org1.collaborators.repo1: cycle with field: orgBotUser):
224-
// ./issue3828.cue:18:33
221+
repo1: (struct){
222+
bot1: (bool){ true }
225223
}
226224
}
227225
}
@@ -264,31 +262,7 @@ diff old new
264262
}
265263
#ID: (_|_){
266264
// [incomplete] noCycleError.foo.bar.#ID: invalid interpolation: non-concrete value string (type string):
267-
@@ -100,8 +100,9 @@
268-
issue3828: (struct){
269-
reduced: (struct){
270-
a: (struct){
271-
- b: (struct){
272-
- foobot1: (bool){ true }
273-
+ b: (_|_){
274-
+ // [incomplete] issue3828.reduced.a.b: key value of dynamic field must be concrete, found _|_(issue3828.reduced.a.b: cycle with field: x):
275-
+ // ./issue3828.cue:5:5
276-
}
277-
}
278-
str: (string){ "foobot1" }
279-
@@ -114,8 +115,9 @@
280-
}
281-
}
282-
collaborators: (struct){
283-
- repo1: (struct){
284-
- bot1: (bool){ true }
285-
+ repo1: (_|_){
286-
+ // [incomplete] issue3828.full.orgs.org1.collaborators.repo1: key value of dynamic field must be concrete, found _|_(issue3828.full.orgs.org1.collaborators.repo1: cycle with field: orgBotUser):
287-
+ // ./issue3828.cue:18:33
288-
}
289-
}
290-
}
291-
@@ -123,6 +125,9 @@
265+
@@ -123,6 +123,9 @@
292266
botUser: (string){ "bot1" }
293267
}
294268
}
@@ -298,7 +272,7 @@ diff old new
298272
foo: (struct){
299273
b: (struct){
300274
c: (struct){
301-
@@ -130,7 +135,4 @@
275+
@@ -130,7 +133,4 @@
302276
}
303277
}
304278
}

internal/core/adt/states.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@ const (
220220
// list value.
221221
scalarConjunct = allTasksCompleted |
222222
scalarKnown |
223-
valueKnown
223+
valueKnown |
224+
disjunctionTask
225+
226+
// a scalarValue is one that is guaranteed to result in a scalar.
227+
// TODO: use more widely instead of scalarKnown.
228+
scalarValue = scalarKnown | disjunctionTask
224229

225230
// needsX condition sets are used to indicate which conditions need to be
226231
// met.

internal/core/adt/tasks.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func processDynamic(ctx *OpContext, t *task, mode runMode) {
145145

146146
field := t.x.(*DynamicField)
147147

148-
v := ctx.scalarValue(t, field.Key)
148+
v := ctx.value(field.Key, combineMode(scalarValue, mode))
149149
if v == nil {
150150
return
151151
}
@@ -182,7 +182,7 @@ func processPatternConstraint(ctx *OpContext, t *task, mode runMode) {
182182

183183
// Note that the result may be a disjunction. Be sure to not take the
184184
// default value as we want to retain the options of the disjunction.
185-
v := ctx.evalState(field.Filter, require(0, scalarKnown))
185+
v := ctx.evalState(field.Filter, require(0, scalarValue))
186186
if v == nil {
187187
return
188188
}

internal/core/export/testdata/main/dynamic.txtar

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bogus field for a failed dynamic field.
137137
}
138138
}
139139
== Final
140-
_|_ // key value of dynamic field must be concrete, found string (and 3 more errors)
140+
_|_ // key value of dynamic field must be concrete, found _|_(cycle error) (and 3 more errors)
141141
== All
142142
{
143143
x: string
@@ -243,7 +243,7 @@ diff old new
243243
+}
244244
== Final
245245
-_|_ // invalid non-ground value string (must be concrete string) (and 1 more errors)
246-
+_|_ // key value of dynamic field must be concrete, found string (and 3 more errors)
246+
+_|_ // key value of dynamic field must be concrete, found _|_(cycle error) (and 3 more errors)
247247
== All
248248
-_|_ // invalid non-ground value string (must be concrete string) (and 1 more errors)
249249
+{

0 commit comments

Comments
 (0)