Skip to content

Commit

Permalink
internal/core/adt: track positions for incomplete types
Browse files Browse the repository at this point in the history
Fixes #1533

Signed-off-by: Marcel van Lohuizen <mpvl@golang.org>

Change-Id: Ib5a358390149d52524446a476be7ed802c969675
Signed-off-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/533460
Reviewed-by: Paul Jolly <paul@myitcv.io>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mpvl committed Feb 22, 2022
1 parent 09c1ee0 commit 2421553
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 18 deletions.
1 change: 1 addition & 0 deletions cmd/cue/cmd/testdata/script/cmd_errpos.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cmp stderr expect-stderr
-- expect-stderr --
command.prompter.contents: invalid bytes argument: non-concrete value string:
./task_tool.cue:9:10
./task_tool.cue:12:13
./task_tool.cue:17:3
tool/file:11:3
command.prompter.filename: invalid string argument: non-concrete value string:
Expand Down
3 changes: 2 additions & 1 deletion cmd/cue/cmd/testdata/script/eval_expr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ cmp stdout expect-stdout
4
-- expect-stderr --
// b.idx
b.idx: invalid non-ground value string (must be concrete string)
b.idx: invalid non-ground value string (must be concrete string):
./partial.cue:8:7
-- partial.cue --
package partial

Expand Down
3 changes: 2 additions & 1 deletion cmd/cue/cmd/testdata/script/export_err.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ cmp stderr expect-stderr
cmp stdout expect-stdout
cmp stderr expect-stderr
-- expect-stderr --
a.b.2.c: incomplete value int
a.b.2.c: incomplete value int:
./exporterr/export_err.cue:3:18
out: invalid interpolation: undefined field: d:
./exporterr/export_err.cue:7:6
./exporterr/export_err.cue:7:16
Expand Down
1 change: 1 addition & 0 deletions cmd/cue/cmd/testdata/script/issue315.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cmp stderr expect-stderr
-- expect-stderr --
invalid interpolation: non-concrete value string (type string):
./file.cue:12:1
./file.cue:3:5
-- file.cue --
#X: {
x: string
Expand Down
6 changes: 4 additions & 2 deletions cmd/cue/cmd/testdata/script/vet_concrete.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
! cue vet -c
cmp stderr expect-stderr
-- expect-stderr --
b.idx: invalid non-ground value string (must be concrete string)
b.str: incomplete value string
b.str: incomplete value string:
./partial.cue:8:7
sum: incomplete value 1 | 2
b.idx: invalid non-ground value string (must be concrete string):
./partial.cue:8:7
-- partial.cue --
package partial

Expand Down
3 changes: 2 additions & 1 deletion cmd/cue/cmd/testdata/script/vet_expr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
cmp stderr expect-stderr

-- expect-stderr --
translations.hello.lang: incomplete value string
translations.hello.lang: incomplete value string:
./vet.cue:3:11
field not allowed: skip:
./data.yaml:20:1
./vet.cue:1:8
Expand Down
6 changes: 4 additions & 2 deletions cmd/cue/cmd/testdata/script/vet_file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ cmp stderr expect-stderr
cmp stderr expect-stderr2

-- expect-stderr --
translations.hello.lang: incomplete value string
translations.hello.lang: incomplete value string:
./vet.cue:3:31
translations.hello.lang: conflicting values false and string (mismatched types bool and string):
./data.yaml:13:11
./vet.cue:3:25
./vet.cue:3:31
-- expect-stderr2 --
translations.hello.lang: incomplete value string
translations.hello.lang: incomplete value string:
./vet.cue:3:31
translations.hello.lang: conflicting values false and string (mismatched types bool and string):
./data.yaml:13:11
./vet.cue:3:25
Expand Down
3 changes: 2 additions & 1 deletion cue/testdata/builtins/056_issue314.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ x:
#V: (#struct){
s: (string){ string }
out: (_|_){
// [incomplete] cannot convert incomplete value "string" to JSON
// [incomplete] cannot convert incomplete value "string" to JSON:
// ./in.cue:20:7
}
}
#U: (#struct){
Expand Down
1 change: 1 addition & 0 deletions cue/testdata/comprehensions/fields.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ issue560: {
tags_map: (_|_){
// [incomplete] error in call to strings.Split: non-concrete value string:
// ./in.cue:14:25
// ./in.cue:12:19
"{a}": (string){ string }
}
}
Expand Down
2 changes: 2 additions & 0 deletions cue/testdata/comprehensions/iferror.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ wrongConcreteType: cannot use 2 (type int) as type bool:
./in.cue:1:9
wrongType: cannot use int (type int) as type bool:
./in.cue:10:2
./in.cue:1:15

Result:
(_|_){
Expand All @@ -133,6 +134,7 @@ Result:
wrongType: (_|_){
// [eval] wrongType: cannot use int (type int) as type bool:
// ./in.cue:10:2
// ./in.cue:1:15
}
incomplete: (_|_){
// [incomplete] incomplete: undefined field: d:
Expand Down
3 changes: 2 additions & 1 deletion cue/testdata/comprehensions/incomplete.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ c: { for x in top {} }
}
top: (_){ _ }
a: (_|_){
// [incomplete] a: incomplete bool: bool
// [incomplete] a: incomplete bool: bool:
// ./in.cue:1:7
}
b: (_|_){
// [incomplete] b: undefined field: foo:
Expand Down
5 changes: 5 additions & 0 deletions cue/testdata/eval/github.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ import "strings"
res: (_|_){
// [incomplete] invalid interpolation: cannot convert incomplete value "string" to JSON:
// ./workflows.cue:127:9
// ./workflows.cue:124:14
}
}
}
Expand Down Expand Up @@ -1314,6 +1315,7 @@ import "strings"
if: (_|_){
// [incomplete] workflows.1.schema._#dispatchJob.if: invalid interpolation: non-concrete value string (type string):
// ./workflows.cue:138:14
// ./workflows.cue:136:14
}
}
name: (string){ "Repository Dispatch" }
Expand Down Expand Up @@ -1755,6 +1757,7 @@ import "strings"
res: (_|_){
// [incomplete] invalid interpolation: cannot convert incomplete value "string" to JSON:
// ./workflows.cue:127:9
// ./workflows.cue:124:14
}
}
}
Expand Down Expand Up @@ -1828,6 +1831,7 @@ import "strings"
if: (_|_){
// [incomplete] repository_dispatch._#dispatchJob.if: invalid interpolation: non-concrete value string (type string):
// ./workflows.cue:138:14
// ./workflows.cue:136:14
}
}
name: (string){ "Repository Dispatch" }
Expand Down Expand Up @@ -2127,6 +2131,7 @@ import "strings"
run: (_|_){
// [incomplete] _#setGoBuildTags.run: invalid interpolation: non-concrete value string (type string):
// ./workflows.cue:261:10
// ./workflows.cue:259:10
}
}
_#installGo(:ci): (#struct){
Expand Down
3 changes: 2 additions & 1 deletion cue/testdata/export/021.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ a: {
(struct){
b: (struct){
idx: (_|_){
// [incomplete] b.idx: invalid non-ground value string (must be concrete string)
// [incomplete] b.idx: invalid non-ground value string (must be concrete string):
// ./in.cue:4:8
}
str: (string){ string }
a: (struct){
Expand Down
3 changes: 2 additions & 1 deletion cue/testdata/export/025.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ c: *1 | 2
-- out/eval --
(struct){
b: (_|_){
// [incomplete] b: invalid non-ground value int (must be concrete int)
// [incomplete] b: invalid non-ground value int (must be concrete int):
// ./in.cue:8:5
}
a: (int){ int }
c: (int){ |(*(int){ 1 }, (int){ 2 }) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ s3: strings.ContainsAny(str, "dd")
s1: (_|_){
// [incomplete] s1: invalid interpolation: non-concrete value string (type string):
// ./in.cue:13:5
// ./in.cue:17:6
}
s2: (string){ strings.ContainsAny("dd") }
s3: (_|_){
// [incomplete] error in call to strings.ContainsAny: non-concrete value string:
// ./in.cue:15:5
// ./in.cue:17:6
}
str: (string){ string }
num: (number){ <4 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ y: _|_ // field "c" not allowed in closed struct
-- out/eval --
(struct){
#a: (_|_){
// [incomplete] #a: incomplete bool: bool
// [incomplete] #a: incomplete bool: bool:
// ./in.cue:5:5
b: (bool){ bool }
}
x: (#struct){
Expand Down
2 changes: 2 additions & 0 deletions cue/testdata/fulleval/044_Issue_#178.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ bar: hex.EncodedLen(len)
foo: (_|_){
// [incomplete] error in call to encoding/csv.Decode: non-concrete value bytes:
// ./in.cue:5:7
// ./in.cue:6:7
}
data: (bytes){ bytes }
len: (int){ int }
bar: (_|_){
// [incomplete] error in call to encoding/hex.EncodedLen: non-concrete value int:
// ./in.cue:9:6
// ./in.cue:8:6
}
}
-- out/compile --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ b: json.Marshal(foo)
-- out/eval --
(struct){
a: (_|_){
// [incomplete] cannot convert incomplete value "string" to JSON
// [incomplete] cannot convert incomplete value "string" to JSON:
// ./in.cue:3:21
}
foo: (struct){
a: (int){ 3 }
Expand Down
3 changes: 2 additions & 1 deletion cue/testdata/fulleval/052_detectIncompleteJSON.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Val:
// ./in.cue:11:11
}
foobar: (_|_){
// [incomplete] cannot convert incomplete value "string" to JSON
// [incomplete] cannot convert incomplete value "string" to JSON:
// ./in.cue:6:21
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cue/testdata/interpolation/issue487.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ t2: {
name: (_|_){
// [incomplete] t2.#R.name: invalid interpolation: non-concrete value string (type string):
// ./in.cue:11:9
// ./in.cue:10:9
}
}
a: (#struct){
Expand Down
1 change: 1 addition & 0 deletions encoding/protobuf/jsonpb/testdata/decoder/enums.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ enum.tooLarge: invalid enum index: 4111222333444555666777888999: greater than ma
errors.cue:5:17
badEnum: invalid string enum: non-concrete value string:
schema.cue:23:10
schema.cue:23:12
6 changes: 5 additions & 1 deletion internal/core/adt/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,12 @@ func (n *nodeContext) getValidators() BaseValue {
a = append(a, c)
kind &= c.Kind()
}

if kind&^n.kind != 0 {
a = append(a, &BasicType{K: n.kind})
a = append(a, &BasicType{
Src: n.kindExpr.Source(), // TODO:Is this always a BasicType?
K: n.kind,
})
}

var v BaseValue
Expand Down
3 changes: 3 additions & 0 deletions internal/core/adt/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ module: "example.com"
v.Finalize(ctx)
adt.Verbosity = 0

// b := validate.Validate(ctx, v, &validate.Config{Concrete: true})
// t.Log(errors.Details(b.Err, nil))

t.Error(debug.NodeString(r, v, nil))

t.Log(ctx.Stats())
Expand Down
2 changes: 1 addition & 1 deletion internal/core/adt/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (x *Top) Kind() Kind { return TopKind }
// bool
//
type BasicType struct {
Src *ast.Ident
Src ast.Node
K Kind
}

Expand Down
4 changes: 2 additions & 2 deletions internal/core/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestValidate(t *testing.T) {
#foo: { use: string }
`,
lookup: "#foo",
out: "incomplete\n#foo.use: incomplete value string",
out: "incomplete\n#foo.use: incomplete value string:\n test:2:16",
}, {
desc: "definitions not considered for completeness",
cfg: &Config{Concrete: true},
Expand Down Expand Up @@ -171,7 +171,7 @@ y: conflicting values 4 and 2:
a: int
}
`,
out: "incomplete\nx.a: incomplete value int",
out: "incomplete\nx.a: incomplete value int:\n test:3:7",
}, {
desc: "pick up non-concrete value in default",
cfg: &Config{Concrete: true},
Expand Down
1 change: 1 addition & 0 deletions pkg/encoding/yaml/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ a: error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3):
yaml.Validate:3:5
b: error in call to encoding/yaml.Validate: incomplete value int:
./in.cue:5:5
./in.cue:5:38
a: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound <3):
./in.cue:6:5
./in.cue:6:48
Expand Down

0 comments on commit 2421553

Please sign in to comment.