Skip to content

Commit

Permalink
interal/core/adt: improve error locations
Browse files Browse the repository at this point in the history
link parents for literal structs and lists

This is not so relevant now, but will be with the comprehension
rework.

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

Change-Id: I4fce69f765a37990dfb7a0f48f150e6bc3c53937
Signed-off-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/529865
Reviewed-by: Paul Jolly <paul@myitcv.io>
  • Loading branch information
mpvl committed Feb 16, 2022
1 parent 4136481 commit b67dc4d
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 71 deletions.
4 changes: 2 additions & 2 deletions cue/testdata/builtins/all.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Errors:
fatalArg.x: invalid operands "eee" and 'eee' to '+' (type string and bytes):
./in.cue:3:12
./in.cue:3:20
0.a: undefined field: c:
fatalChild.0.a: undefined field: c:
./in.cue:9:20

Result:
Expand All @@ -42,7 +42,7 @@ Result:
#b: (#struct){
}
x: (_|_){
// [eval] 0.a: undefined field: c:
// [eval] fatalChild.0.a: undefined field: c:
// ./in.cue:9:20
}
}
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/builtins/incomplete.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Result:
// ./in.cue:50:23
}
max: (_|_){
// [incomplete] 0: operand param of '+' not concrete (was int):
// [incomplete] incompleteArgDecimalList.#a.0: operand param of '+' not concrete (was int):
// ./in.cue:50:23
}
}
Expand All @@ -211,7 +211,7 @@ Result:
// ./in.cue:58:9
}
joined: (_|_){
// [incomplete] 0: non-concrete value string in operand to +:
// [incomplete] incompleteArgStringList.#a.0: non-concrete value string in operand to +:
// ./in.cue:59:22
// ./in.cue:58:9
}
Expand Down
129 changes: 64 additions & 65 deletions cue/testdata/cycle/structural.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ d2: {
}

d3: {
// TODO(errors): correct position reporting in structural cycle.
config: {
a: b: c: indirect
indirect: [a.b, null][i]
Expand Down Expand Up @@ -462,72 +461,72 @@ e1.b.c: structural cycle
e2.a.c: structural cycle
e2.b.c: structural cycle
e3.a: conflicting values [a] and {c:a} (mismatched types list and struct):
./in.cue:304:8
./in.cue:305:8
./in.cue:306:8
e3.a.0: conflicting values [a] and {c:a} (mismatched types list and struct):
./in.cue:304:8
./in.cue:304:9
./in.cue:305:8
./in.cue:305:9
./in.cue:306:8
e3.a.0: structural cycle
e3.a.c: conflicting values [a] and {c:a} (mismatched types list and struct):
./in.cue:304:8
./in.cue:305:8
./in.cue:306:8
./in.cue:306:11
./in.cue:305:11
e3.a.c: structural cycle
e3.b: conflicting values [b] and {c:b} (mismatched types list and struct):
./in.cue:307:8
./in.cue:308:8
./in.cue:309:8
e3.b.0: conflicting values [b] and {c:b} (mismatched types list and struct):
./in.cue:307:8
./in.cue:307:9
./in.cue:308:8
./in.cue:308:9
./in.cue:309:8
e3.b.0: structural cycle
e3.b.c: conflicting values [b] and {c:b} (mismatched types list and struct):
./in.cue:307:8
./in.cue:308:8
./in.cue:309:8
./in.cue:309:11
./in.cue:308:11
e3.b.c: structural cycle
e4.a.0: 4 errors in empty disjunction:
e4.a.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
./in.cue:313:13
./in.cue:314:9
./in.cue:312:13
./in.cue:313:9
e4.a.0.0: 2 errors in empty disjunction:
e4.a.0.0: conflicting values [[{c:1}]] and {c:1} (mismatched types list and struct):
./in.cue:314:8
./in.cue:314:10
./in.cue:313:8
./in.cue:313:10
e4.a.0.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
./in.cue:312:9
./in.cue:312:13
./in.cue:313:9
./in.cue:313:13
./in.cue:314:9
e4.b.0: 4 errors in empty disjunction:
e4.b.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
./in.cue:316:9
./in.cue:317:13
./in.cue:315:9
./in.cue:316:13
e4.b.0.0: 2 errors in empty disjunction:
e4.b.0.0: conflicting values [(b|{})] and {c:1} (mismatched types list and struct):
./in.cue:316:10
./in.cue:317:8
./in.cue:315:10
./in.cue:316:8
e4.b.0.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
./in.cue:315:9
./in.cue:316:9
./in.cue:317:9
./in.cue:317:13
./in.cue:316:13
nestedList.v1e.y.0: 4 errors in empty disjunction:
nestedList.v1e.y.0: conflicting values int and [[2],1] (mismatched types int and list):
./in.cue:332:17
./in.cue:333:17
./in.cue:334:17
nestedList.v1e.y.0.0: 2 errors in empty disjunction:
nestedList.v1e.y.0.0: conflicting values int and [2] (mismatched types int and list):
./in.cue:333:17
./in.cue:334:18
./in.cue:332:17
./in.cue:333:18
nestedList.v1e.y.0.0: incompatible list lengths (1 and 2)
nestedList.v2e.y.0: 4 errors in empty disjunction:
nestedList.v2e.y.0: conflicting values int and [[2],1] (mismatched types int and list):
./in.cue:337:17
./in.cue:338:17
./in.cue:339:17
nestedList.v2e.y.0.0: 2 errors in empty disjunction:
nestedList.v2e.y.0.0: conflicting values int and [2] (mismatched types int and list):
./in.cue:338:18
./in.cue:339:17
./in.cue:337:18
./in.cue:338:17
nestedList.v2e.y.0.0: incompatible list lengths (1 and 2)
p2.#T.a.b.link: structural cycle
p3.#U.#T.a.b.link: structural cycle
Expand All @@ -537,8 +536,8 @@ z1.z.f.h.h: structural cycle
z1.z.g.h: structural cycle
cycle error:
./in.cue:141:10
0: structural cycle:
./in.cue:280:19
d3.config.0: structural cycle:
./in.cue:279:19

Result:
(_|_){
Expand Down Expand Up @@ -1148,20 +1147,20 @@ Result:
b: (_|_){
// [structural cycle]
c: (_|_){
// [structural cycle] 0: structural cycle:
// ./in.cue:280:19
// [structural cycle] d3.config.0: structural cycle:
// ./in.cue:279:19
}
}
}
indirect: (_|_){
// [structural cycle] 0: structural cycle:
// ./in.cue:280:19
// [structural cycle] d3.config.0: structural cycle:
// ./in.cue:279:19
}
i: (int){ |(*(int){ 1 }, (int){ int }) }
}
x: (_|_){
// [structural cycle] 0: structural cycle:
// ./in.cue:280:19
// [structural cycle] d3.config.0: structural cycle:
// ./in.cue:279:19
i: (int){ 0 }
}
}
Expand Down Expand Up @@ -1199,39 +1198,39 @@ Result:
// [eval]
a: (_|_){
// [eval] e3.a: conflicting values [a] and {c:a} (mismatched types list and struct):
// ./in.cue:304:8
// ./in.cue:305:8
// ./in.cue:306:8
c: (_|_){
// [eval] e3.a.c: conflicting values [a] and {c:a} (mismatched types list and struct):
// ./in.cue:304:8
// ./in.cue:305:8
// ./in.cue:306:8
// ./in.cue:306:11
// ./in.cue:305:11
// e3.a.c: structural cycle
}
0: (_|_){
// [eval] e3.a.0: conflicting values [a] and {c:a} (mismatched types list and struct):
// ./in.cue:304:8
// ./in.cue:304:9
// ./in.cue:305:8
// ./in.cue:305:9
// ./in.cue:306:8
// e3.a.0: structural cycle
}
}
b: (_|_){
// [eval] e3.b: conflicting values [b] and {c:b} (mismatched types list and struct):
// ./in.cue:307:8
// ./in.cue:308:8
// ./in.cue:309:8
c: (_|_){
// [eval] e3.b.c: conflicting values [b] and {c:b} (mismatched types list and struct):
// ./in.cue:307:8
// ./in.cue:308:8
// ./in.cue:309:8
// ./in.cue:309:11
// ./in.cue:308:11
// e3.b.c: structural cycle
}
0: (_|_){
// [eval] e3.b.0: conflicting values [b] and {c:b} (mismatched types list and struct):
// ./in.cue:307:8
// ./in.cue:307:9
// ./in.cue:308:8
// ./in.cue:308:9
// ./in.cue:309:8
// e3.b.0: structural cycle
}
}
Expand All @@ -1243,16 +1242,16 @@ Result:
0: (_|_){
// [eval] e4.a.0: 4 errors in empty disjunction:
// e4.a.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// ./in.cue:313:13
// ./in.cue:314:9
// ./in.cue:312:13
// ./in.cue:313:9
// e4.a.0.0: 2 errors in empty disjunction:
// e4.a.0.0: conflicting values [[{c:1}]] and {c:1} (mismatched types list and struct):
// ./in.cue:314:8
// ./in.cue:314:10
// ./in.cue:313:8
// ./in.cue:313:10
// e4.a.0.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// ./in.cue:312:9
// ./in.cue:312:13
// ./in.cue:313:9
// ./in.cue:313:13
// ./in.cue:314:9
0: (struct){
c: (int){ 1 }
}
Expand All @@ -1263,16 +1262,16 @@ Result:
0: (_|_){
// [eval] e4.b.0: 4 errors in empty disjunction:
// e4.b.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// ./in.cue:316:9
// ./in.cue:317:13
// ./in.cue:315:9
// ./in.cue:316:13
// e4.b.0.0: 2 errors in empty disjunction:
// e4.b.0.0: conflicting values [(b|{})] and {c:1} (mismatched types list and struct):
// ./in.cue:316:10
// ./in.cue:317:8
// ./in.cue:315:10
// ./in.cue:316:8
// e4.b.0.0: conflicting values [{c:1}] and {} (mismatched types list and struct):
// ./in.cue:315:9
// ./in.cue:316:9
// ./in.cue:317:9
// ./in.cue:317:13
// ./in.cue:316:13
0: (struct){
c: (int){ 1 }
}
Expand Down Expand Up @@ -1300,12 +1299,12 @@ Result:
0: (_|_){
// [eval] nestedList.v1e.y.0: 4 errors in empty disjunction:
// nestedList.v1e.y.0: conflicting values int and [[2],1] (mismatched types int and list):
// ./in.cue:332:17
// ./in.cue:333:17
// ./in.cue:334:17
// nestedList.v1e.y.0.0: 2 errors in empty disjunction:
// nestedList.v1e.y.0.0: conflicting values int and [2] (mismatched types int and list):
// ./in.cue:333:17
// ./in.cue:334:18
// ./in.cue:332:17
// ./in.cue:333:18
// nestedList.v1e.y.0.0: incompatible list lengths (1 and 2)
0: (#list){
0: (int){ 2 }
Expand All @@ -1322,12 +1321,12 @@ Result:
0: (_|_){
// [eval] nestedList.v2e.y.0: 4 errors in empty disjunction:
// nestedList.v2e.y.0: conflicting values int and [[2],1] (mismatched types int and list):
// ./in.cue:337:17
// ./in.cue:338:17
// ./in.cue:339:17
// nestedList.v2e.y.0.0: 2 errors in empty disjunction:
// nestedList.v2e.y.0.0: conflicting values int and [2] (mismatched types int and list):
// ./in.cue:338:18
// ./in.cue:339:17
// ./in.cue:337:18
// ./in.cue:338:17
// nestedList.v2e.y.0.0: incompatible list lengths (1 and 2)
0: (#list){
0: (int){ 2 }
Expand Down
33 changes: 33 additions & 0 deletions cue/testdata/eval/comprehensions.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- in.cue --
import "strings"

a: { x: 10, y: 100, z: 50 }
b: {
for k, v in a if v <= 50 {
Expand All @@ -19,6 +21,16 @@ c: {
"\(k)": y
}
}

A: X: run: "dfoo"

if true {
A: X: {
run: string
files: "\(strings.Join([ run ], "\n"))"
}
}

-- out/eval --
(struct){
a: (struct){
Expand All @@ -36,6 +48,12 @@ c: {
y: (int){ 110 }
z: (int){ 60 }
}
A: (struct){
X: (struct){
run: (string){ "dfoo" }
files: (string){ "dfoo" }
}
}
}
-- out/compile --
--- in.cue
Expand Down Expand Up @@ -63,4 +81,19 @@ c: {
"\(〈2;k〉)": 〈1;y〉
}
}
A: {
X: {
run: "dfoo"
}
}
if true {
A: {
X: {
run: string
files: "\(〈import;strings〉.Join([
〈1;run〉,
], "\n"))"
}
}
}
}
5 changes: 5 additions & 0 deletions internal/core/adt/closed2.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func isComplexStruct(ctx *OpContext, v *Vertex) bool {
// TODO: cleanup code and error messages. Reduce duplication in some related
// code.
func verifyArc2(ctx *OpContext, f Feature, v *Vertex, isClosed bool) (found bool, err *Bottom) {
// Don't check computed, temporary vertices.
if v.Label == InvalidLabel {
return true, nil
}

// TODO(perf): collect positions in error.
defer ctx.ReleasePositions(ctx.MarkPositions())

Expand Down
Loading

0 comments on commit b67dc4d

Please sign in to comment.