Skip to content

Commit 0e634cf

Browse files
committed
internal/core/adt: report error for integer fields
These are currently not supported. Fixes #1516 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Change-Id: I41529d4068a580e9bbc593f8743cb0e5987c8912 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/533472 Reviewed-by: Paul Jolly <paul@myitcv.io>
1 parent 84d3cad commit 0e634cf

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

cue/testdata/comprehensions/errors.txtar

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@ userError: {
2222
if a != "" {
2323
}
2424
}
25+
26+
intField: {
27+
for i, _ in [1, 2] {
28+
(i): {
29+
}
30+
}
31+
}
2532
-- out/eval --
2633
Errors:
2734
circularFor.#list: invalid operand tail != null (found bool, want list or struct):
2835
./in.cue:12:18
36+
intField: integer fields not supported:
37+
./in.cue:27:4
2938

3039
Result:
3140
(_|_){
@@ -51,6 +60,14 @@ Result:
5160
// ./in.cue:20:8
5261
a: (string){ string }
5362
}
63+
intField: (_|_){
64+
// [eval] intField: integer fields not supported:
65+
// ./in.cue:27:4
66+
0: (struct){
67+
}
68+
1: (struct){
69+
}
70+
}
5471
}
5572
-- out/compile --
5673
--- in.cue
@@ -71,4 +88,12 @@ Result:
7188
a: (string|*_|_(explicit error (_|_ literal) in source))
7289
if (〈0;a〉 != "") {}
7390
}
91+
intField: {
92+
for i, _ in [
93+
1,
94+
2,
95+
] {
96+
〈1;i〉: {}
97+
}
98+
}
7499
}

cue/testdata/eval/fields.txtar

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ bulkToSelf: {
55
foo: bar: "3" // error
66
}
77
}
8+
intField: {
9+
(2): string
10+
}
811
-- out/compile --
912
--- in.cue
1013
{
@@ -18,12 +21,17 @@ bulkToSelf: {
1821
}
1922
}
2023
}
24+
intField: {
25+
2: string
26+
}
2127
}
2228
-- out/eval --
2329
Errors:
2430
bulkToSelf.a.foo.bar: conflicting values "3" and int (mismatched types string and int):
2531
./in.cue:3:24
2632
./in.cue:4:19
33+
intField: integer fields not supported:
34+
./in.cue:8:3
2735

2836
Result:
2937
(_|_){
@@ -42,4 +50,9 @@ Result:
4250
}
4351
}
4452
}
53+
intField: (_|_){
54+
// [eval] intField: integer fields not supported:
55+
// ./in.cue:8:3
56+
2: (string){ string }
57+
}
4558
}

internal/core/adt/eval.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,9 @@ func (n *nodeContext) injectDynamic() (progress bool) {
19581958
continue
19591959
}
19601960
f = ctx.Label(d.field.Key, v)
1961+
if f.IsInt() {
1962+
n.addErr(ctx.NewPosf(pos(d.field.Key), "integer fields not supported"))
1963+
}
19611964
n.insertField(f, MakeConjunct(d.env, d.field, d.id))
19621965
}
19631966

0 commit comments

Comments
 (0)