From 2421553ac4909481cf5235616add5a83e059daa5 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Fri, 18 Feb 2022 19:55:18 +0100 Subject: [PATCH] internal/core/adt: track positions for incomplete types Fixes #1533 Signed-off-by: Marcel van Lohuizen Change-Id: Ib5a358390149d52524446a476be7ed802c969675 Signed-off-by: Marcel van Lohuizen Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/533460 Reviewed-by: Paul Jolly Unity-Result: CUEcueckoo TryBot-Result: CUEcueckoo --- cmd/cue/cmd/testdata/script/cmd_errpos.txt | 1 + cmd/cue/cmd/testdata/script/eval_expr.txt | 3 ++- cmd/cue/cmd/testdata/script/export_err.txt | 3 ++- cmd/cue/cmd/testdata/script/issue315.txt | 1 + cmd/cue/cmd/testdata/script/vet_concrete.txt | 6 ++++-- cmd/cue/cmd/testdata/script/vet_expr.txt | 3 ++- cmd/cue/cmd/testdata/script/vet_file.txt | 6 ++++-- cue/testdata/builtins/056_issue314.txtar | 3 ++- cue/testdata/comprehensions/fields.txtar | 1 + cue/testdata/comprehensions/iferror.txtar | 2 ++ cue/testdata/comprehensions/incomplete.txtar | 3 ++- cue/testdata/eval/github.txtar | 5 +++++ cue/testdata/export/021.txtar | 3 ++- cue/testdata/export/025.txtar | 3 ++- ...6_dont_convert_incomplete_errors_to_non-incomplete.txtar | 2 ++ .../fulleval/042_cross-dependent_comprehension.txtar | 3 ++- cue/testdata/fulleval/044_Issue_#178.txtar | 2 ++ .../fulleval/050_json_Marshaling_detects_incomplete.txtar | 3 ++- cue/testdata/fulleval/052_detectIncompleteJSON.txtar | 3 ++- cue/testdata/interpolation/issue487.txtar | 1 + encoding/protobuf/jsonpb/testdata/decoder/enums.txtar | 1 + internal/core/adt/eval.go | 6 +++++- internal/core/adt/eval_test.go | 3 +++ internal/core/adt/expr.go | 2 +- internal/core/validate/validate_test.go | 4 ++-- pkg/encoding/yaml/testdata/gen.txtar | 1 + 26 files changed, 56 insertions(+), 18 deletions(-) diff --git a/cmd/cue/cmd/testdata/script/cmd_errpos.txt b/cmd/cue/cmd/testdata/script/cmd_errpos.txt index f2db94818b5..0234cb48820 100644 --- a/cmd/cue/cmd/testdata/script/cmd_errpos.txt +++ b/cmd/cue/cmd/testdata/script/cmd_errpos.txt @@ -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: diff --git a/cmd/cue/cmd/testdata/script/eval_expr.txt b/cmd/cue/cmd/testdata/script/eval_expr.txt index c4e103f8239..74c984a567f 100644 --- a/cmd/cue/cmd/testdata/script/eval_expr.txt +++ b/cmd/cue/cmd/testdata/script/eval_expr.txt @@ -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 diff --git a/cmd/cue/cmd/testdata/script/export_err.txt b/cmd/cue/cmd/testdata/script/export_err.txt index 93a512671fa..1f0919e84ae 100644 --- a/cmd/cue/cmd/testdata/script/export_err.txt +++ b/cmd/cue/cmd/testdata/script/export_err.txt @@ -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 diff --git a/cmd/cue/cmd/testdata/script/issue315.txt b/cmd/cue/cmd/testdata/script/issue315.txt index 7442ffe1c36..ec10bf1181e 100644 --- a/cmd/cue/cmd/testdata/script/issue315.txt +++ b/cmd/cue/cmd/testdata/script/issue315.txt @@ -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 diff --git a/cmd/cue/cmd/testdata/script/vet_concrete.txt b/cmd/cue/cmd/testdata/script/vet_concrete.txt index d239291a6db..10f6872b008 100644 --- a/cmd/cue/cmd/testdata/script/vet_concrete.txt +++ b/cmd/cue/cmd/testdata/script/vet_concrete.txt @@ -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 diff --git a/cmd/cue/cmd/testdata/script/vet_expr.txt b/cmd/cue/cmd/testdata/script/vet_expr.txt index 28b08a48438..4c31b370c9f 100644 --- a/cmd/cue/cmd/testdata/script/vet_expr.txt +++ b/cmd/cue/cmd/testdata/script/vet_expr.txt @@ -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 diff --git a/cmd/cue/cmd/testdata/script/vet_file.txt b/cmd/cue/cmd/testdata/script/vet_file.txt index d5e5fcd79a9..4d3ca987e23 100644 --- a/cmd/cue/cmd/testdata/script/vet_file.txt +++ b/cmd/cue/cmd/testdata/script/vet_file.txt @@ -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 diff --git a/cue/testdata/builtins/056_issue314.txtar b/cue/testdata/builtins/056_issue314.txtar index 5ae728a116a..8f9fc828903 100644 --- a/cue/testdata/builtins/056_issue314.txtar +++ b/cue/testdata/builtins/056_issue314.txtar @@ -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){ diff --git a/cue/testdata/comprehensions/fields.txtar b/cue/testdata/comprehensions/fields.txtar index 641663d2881..6dc212ea76a 100644 --- a/cue/testdata/comprehensions/fields.txtar +++ b/cue/testdata/comprehensions/fields.txtar @@ -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 } } } diff --git a/cue/testdata/comprehensions/iferror.txtar b/cue/testdata/comprehensions/iferror.txtar index 70f4f89fcc3..dd41e6891a0 100644 --- a/cue/testdata/comprehensions/iferror.txtar +++ b/cue/testdata/comprehensions/iferror.txtar @@ -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: (_|_){ @@ -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: diff --git a/cue/testdata/comprehensions/incomplete.txtar b/cue/testdata/comprehensions/incomplete.txtar index 7bb9a21ea66..a68b75dd570 100644 --- a/cue/testdata/comprehensions/incomplete.txtar +++ b/cue/testdata/comprehensions/incomplete.txtar @@ -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: diff --git a/cue/testdata/eval/github.txtar b/cue/testdata/eval/github.txtar index 0f80bbec46e..ab1ac6ad4ca 100644 --- a/cue/testdata/eval/github.txtar +++ b/cue/testdata/eval/github.txtar @@ -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 } } } @@ -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" } @@ -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 } } } @@ -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" } @@ -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){ diff --git a/cue/testdata/export/021.txtar b/cue/testdata/export/021.txtar index 822ef79fcf1..ea1398bf3fd 100644 --- a/cue/testdata/export/021.txtar +++ b/cue/testdata/export/021.txtar @@ -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){ diff --git a/cue/testdata/export/025.txtar b/cue/testdata/export/025.txtar index 5093bf350c9..ac1ec0bbf97 100644 --- a/cue/testdata/export/025.txtar +++ b/cue/testdata/export/025.txtar @@ -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 }) } diff --git a/cue/testdata/fulleval/026_dont_convert_incomplete_errors_to_non-incomplete.txtar b/cue/testdata/fulleval/026_dont_convert_incomplete_errors_to_non-incomplete.txtar index 243fe7f631a..20bc1c361fd 100644 --- a/cue/testdata/fulleval/026_dont_convert_incomplete_errors_to_non-incomplete.txtar +++ b/cue/testdata/fulleval/026_dont_convert_incomplete_errors_to_non-incomplete.txtar @@ -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 } diff --git a/cue/testdata/fulleval/042_cross-dependent_comprehension.txtar b/cue/testdata/fulleval/042_cross-dependent_comprehension.txtar index 55be401ab00..d17aaacf425 100644 --- a/cue/testdata/fulleval/042_cross-dependent_comprehension.txtar +++ b/cue/testdata/fulleval/042_cross-dependent_comprehension.txtar @@ -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){ diff --git a/cue/testdata/fulleval/044_Issue_#178.txtar b/cue/testdata/fulleval/044_Issue_#178.txtar index 9f196683ed9..457c21224e3 100644 --- a/cue/testdata/fulleval/044_Issue_#178.txtar +++ b/cue/testdata/fulleval/044_Issue_#178.txtar @@ -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 -- diff --git a/cue/testdata/fulleval/050_json_Marshaling_detects_incomplete.txtar b/cue/testdata/fulleval/050_json_Marshaling_detects_incomplete.txtar index f8a8193b5eb..e1b9243788e 100644 --- a/cue/testdata/fulleval/050_json_Marshaling_detects_incomplete.txtar +++ b/cue/testdata/fulleval/050_json_Marshaling_detects_incomplete.txtar @@ -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 } diff --git a/cue/testdata/fulleval/052_detectIncompleteJSON.txtar b/cue/testdata/fulleval/052_detectIncompleteJSON.txtar index 9996182bd8a..15704f5b2ef 100644 --- a/cue/testdata/fulleval/052_detectIncompleteJSON.txtar +++ b/cue/testdata/fulleval/052_detectIncompleteJSON.txtar @@ -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 } } } diff --git a/cue/testdata/interpolation/issue487.txtar b/cue/testdata/interpolation/issue487.txtar index 81a181a7f58..63ef66acd19 100644 --- a/cue/testdata/interpolation/issue487.txtar +++ b/cue/testdata/interpolation/issue487.txtar @@ -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){ diff --git a/encoding/protobuf/jsonpb/testdata/decoder/enums.txtar b/encoding/protobuf/jsonpb/testdata/decoder/enums.txtar index e3c41595c3e..deace5f46f1 100644 --- a/encoding/protobuf/jsonpb/testdata/decoder/enums.txtar +++ b/encoding/protobuf/jsonpb/testdata/decoder/enums.txtar @@ -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 diff --git a/internal/core/adt/eval.go b/internal/core/adt/eval.go index 9f8bb31e393..41065a4d199 100644 --- a/internal/core/adt/eval.go +++ b/internal/core/adt/eval.go @@ -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 diff --git a/internal/core/adt/eval_test.go b/internal/core/adt/eval_test.go index 0356e337d02..264abe8a51d 100644 --- a/internal/core/adt/eval_test.go +++ b/internal/core/adt/eval_test.go @@ -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()) diff --git a/internal/core/adt/expr.go b/internal/core/adt/expr.go index d4fe366c0d3..31aeda234f5 100644 --- a/internal/core/adt/expr.go +++ b/internal/core/adt/expr.go @@ -425,7 +425,7 @@ func (x *Top) Kind() Kind { return TopKind } // bool // type BasicType struct { - Src *ast.Ident + Src ast.Node K Kind } diff --git a/internal/core/validate/validate_test.go b/internal/core/validate/validate_test.go index 60f8d6aaab6..6928e49e870 100644 --- a/internal/core/validate/validate_test.go +++ b/internal/core/validate/validate_test.go @@ -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}, @@ -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}, diff --git a/pkg/encoding/yaml/testdata/gen.txtar b/pkg/encoding/yaml/testdata/gen.txtar index 65b5f1f7b6c..29968830769 100644 --- a/pkg/encoding/yaml/testdata/gen.txtar +++ b/pkg/encoding/yaml/testdata/gen.txtar @@ -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