Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/eval: add more positions for closedness errors
Browse files Browse the repository at this point in the history
- Keep track of position stack in context.
- Copy the positions on first use.

Change-Id: Ibaab87557353484d62277cd08f7f2f7fc619f9c9
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6682
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
  • Loading branch information
mpvl committed Jul 25, 2020
1 parent fbc6f86 commit cfc6c8c
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 93 deletions.
22 changes: 18 additions & 4 deletions cue/testdata/definitions/026_combined_definitions.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ d1: #D1 & {
}
-- out/eval --
Errors:
#D4.env: field `b` not allowed
d1.env: field `c` not allowed
#D4.env: field `b` not allowed:
./in.cue:27:7
./in.cue:30:1
./in.cue:30:6
d1.env: field `c` not allowed:
./in.cue:2:1
./in.cue:3:7
./in.cue:4:7
./in.cue:9:17

Result:
(_|_){
Expand All @@ -137,7 +144,11 @@ Result:
d1: (_|_){
// [eval]
env: (_|_){
// [eval] d1.env: field `c` not allowed
// [eval] d1.env: field `c` not allowed:
// ./in.cue:2:1
// ./in.cue:3:7
// ./in.cue:4:7
// ./in.cue:9:17
a: (string){ "A" }
b: (string){ "B" }
c: (string){ "C" }
Expand All @@ -160,7 +171,10 @@ Result:
#D4: (_|_){
// [eval]
env: (_|_){
// [eval] #D4.env: field `b` not allowed
// [eval] #D4.env: field `b` not allowed:
// ./in.cue:27:7
// ./in.cue:30:1
// ./in.cue:30:6
a: (int){ int }
b: (int){ int }
}
Expand Down
12 changes: 10 additions & 2 deletions cue/testdata/definitions/032_definitions_with_embedding.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@
}
-- out/eval --
Errors:
#e1.a: field `d` not allowed
#e1.a: field `d` not allowed:
./in.cue:1:1
./in.cue:2:5
./in.cue:7:5
./in.cue:12:15

Result:
(_|_){
Expand All @@ -101,7 +105,11 @@ Result:
#e1: (_|_){
// [eval]
a: (_|_){
// [eval] #e1.a: field `d` not allowed
// [eval] #e1.a: field `d` not allowed:
// ./in.cue:1:1
// ./in.cue:2:5
// ./in.cue:7:5
// ./in.cue:12:15
b: (int){ int }
c: (int){ int }
d: (int){ 4 }
Expand Down
14 changes: 11 additions & 3 deletions cue/testdata/definitions/033_Issue_#153.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,23 @@ Junk: {
}
-- out/eval --
Errors:
listOfCloseds.0: field `b` not allowed
listOfCloseds.0: field `b` not allowed:
./in.cue:5:1
./in.cue:5:10
./in.cue:14:18
./in.cue:15:20

Result:
(_|_){
// [eval]
listOfCloseds: (_|_){
// [eval]
0: (_|_){
// [eval] listOfCloseds.0: field `b` not allowed
// [eval] listOfCloseds.0: field `b` not allowed:
// ./in.cue:5:1
// ./in.cue:5:10
// ./in.cue:14:18
// ./in.cue:15:20
a: (int){ |(*(int){ 0 }, (int){ int }) }
b: (int){ 2 }
}
Expand All @@ -79,7 +87,7 @@ Result:
listOfCloseds: (list){
}
}
#Closed: (struct){
#Closed: (#struct){
a: (int){ |(*(int){ 0 }, (int){ int }) }
}
Junk: (struct){
Expand Down
22 changes: 18 additions & 4 deletions cue/testdata/definitions/037_closing_with_comprehensions.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,15 @@ a: _|_ // field "f3" not allowed in closed struct
-- out/eval --
Errors:
#D: cannot mix bulk optional fields with dynamic fields, embeddings, or comprehensions within the same struct
#E: field `f3` not allowed
a: field `f3` not allowed
#E: field `f3` not allowed:
./in.cue:1:1
./in.cue:1:5
./in.cue:27:10
./in.cue:28:24
a: field `f3` not allowed:
./in.cue:1:1
./in.cue:1:5
./in.cue:4:10

Result:
(_|_){
Expand All @@ -126,13 +133,20 @@ Result:
f1: (int){ int }
}
#E: (_|_){
// [eval] #E: field `f3` not allowed
// [eval] #E: field `f3` not allowed:
// ./in.cue:1:1
// ./in.cue:1:5
// ./in.cue:27:10
// ./in.cue:28:24
f1: (int){ int }
f2: (int){ int }
f3: (int){ int }
}
a: (_|_){
// [eval] a: field `f3` not allowed
// [eval] a: field `f3` not allowed:
// ./in.cue:1:1
// ./in.cue:1:5
// ./in.cue:4:10
f1: (int){ int }
f2: (int){ int }
f3: (int){ int }
Expand Down
30 changes: 26 additions & 4 deletions cue/testdata/definitions/037_conjunction_of_optional_sets.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,19 @@ d: _|_ // field "aaa" not allowed in closed struct
}
-- out/eval --
Errors:
c: field `aaa` not allowed
d: field `aaa` not allowed
c: field `aaa` not allowed:
./in.cue:1:1
./in.cue:1:5
./in.cue:4:1
./in.cue:4:5
./in.cue:9:10
d: field `aaa` not allowed:
./in.cue:1:1
./in.cue:1:5
./in.cue:4:1
./in.cue:4:5
./in.cue:11:5
./in.cue:12:9

Result:
(_|_){
Expand All @@ -65,13 +76,24 @@ Result:
#C: (#struct){
}
c: (_|_){
// [eval] c: field `aaa` not allowed
// [eval] c: field `aaa` not allowed:
// ./in.cue:1:1
// ./in.cue:1:5
// ./in.cue:4:1
// ./in.cue:4:5
// ./in.cue:9:10
aaa: (int){ 3 }
}
#D: (#struct){
}
d: (_|_){
// [eval] d: field `aaa` not allowed
// [eval] d: field `aaa` not allowed:
// ./in.cue:1:1
// ./in.cue:1:5
// ./in.cue:4:1
// ./in.cue:4:5
// ./in.cue:11:5
// ./in.cue:12:9
aaa: (int){ 3 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ a: #S & {
}
-- out/eval --
Errors:
a.v: field `b` not allowed
a.v: field `b` not allowed:
./in.cue:1:1
./in.cue:2:12
./in.cue:5:5

Result:
(_|_){
Expand All @@ -48,7 +51,10 @@ Result:
a: (_|_){
// [eval]
v: (_|_){
// [eval] a.v: field `b` not allowed
// [eval] a.v: field `b` not allowed:
// ./in.cue:1:1
// ./in.cue:2:12
// ./in.cue:5:5
b: (int){ int }
a: (int){ int }
}
Expand Down
10 changes: 8 additions & 2 deletions cue/testdata/eval/closed_disjunction.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ b: #A & {
}
-- out/eval --
Errors:
b: field `d` not allowed
b: field `d` not allowed:
./in.cue:1:5
./in.cue:3:35
./in.cue:11:9

Result:
(_|_){
Expand All @@ -27,7 +30,10 @@ Result:
c: (int){ 3 }
}
b: (_|_){
// [eval] b: field `d` not allowed
// [eval] b: field `d` not allowed:
// ./in.cue:1:5
// ./in.cue:3:35
// ./in.cue:11:9
c: (int){ 3 }
d: (int){ 4 }
}
Expand Down
12 changes: 10 additions & 2 deletions cue/testdata/eval/closedness.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ a: #A & {
}
-- out/eval --
Errors:
a.q: field `e` not allowed
a.q: field `e` not allowed:
./in.cue:1:1
./in.cue:1:5
./in.cue:6:8
./in.cue:13:8

Result:
(_|_){
Expand All @@ -37,7 +41,11 @@ Result:
// [eval]
b: (int){ 3 }
q: (_|_){
// [eval] a.q: field `e` not allowed
// [eval] a.q: field `e` not allowed:
// ./in.cue:1:1
// ./in.cue:1:5
// ./in.cue:6:8
// ./in.cue:13:8
c: (int){ 2 }
d: (int){ int }
e: (int){ 43 }
Expand Down
36 changes: 30 additions & 6 deletions cue/testdata/fulleval/035_optionals_with_label_filters.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,21 @@ jobs3: _|_ // field "fooTest1" not allowed in closed struct
}
-- out/eval --
Errors:
jobs1: field `foo1` not allowed
jobs3: field `fooTest1` not allowed
jobs3.fooTest1: field `cmd` not allowed
jobs1: field `foo1` not allowed:
./in.cue:6:8
./in.cue:7:2
./in.cue:9:2
./in.cue:16:8
jobs3: field `fooTest1` not allowed:
./in.cue:6:8
./in.cue:7:2
./in.cue:9:2
./in.cue:22:8
./in.cue:23:8
jobs3.fooTest1: field `cmd` not allowed:
./in.cue:2:7
./in.cue:6:8
./in.cue:23:18
jobs2.fooTest.name: invalid value "badName" (out of bound =~"^test"):
./in.cue:9:22

Expand All @@ -124,7 +136,11 @@ Result:
}
}
jobs1: (_|_){
// [eval] jobs1: field `foo1` not allowed
// [eval] jobs1: field `foo1` not allowed:
// ./in.cue:6:8
// ./in.cue:7:2
// ./in.cue:9:2
// ./in.cue:16:8
foo1: (#struct){
}
}
Expand All @@ -140,9 +156,17 @@ Result:
}
}
jobs3: (_|_){
// [eval] jobs3: field `fooTest1` not allowed
// [eval] jobs3: field `fooTest1` not allowed:
// ./in.cue:6:8
// ./in.cue:7:2
// ./in.cue:9:2
// ./in.cue:22:8
// ./in.cue:23:8
fooTest1: (_|_){
// [eval] jobs3.fooTest1: field `cmd` not allowed
// [eval] jobs3.fooTest1: field `cmd` not allowed:
// ./in.cue:2:7
// ./in.cue:6:8
// ./in.cue:23:18
name: (string){ "badName" }
cmd: (string){ string }
}
Expand Down
20 changes: 16 additions & 4 deletions cue/testdata/resolve/025_definitions.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ mixedRec: {
}
-- out/eval --
Errors:
foo: field `feild` not allowed
foo1.recursive: field `feild` not allowed
foo: field `feild` not allowed:
./in.cue:1:1
./in.cue:1:7
./in.cue:13:6
foo1.recursive: field `feild` not allowed:
./in.cue:1:1
./in.cue:3:13
./in.cue:18:13

Result:
(_|_){
Expand All @@ -136,7 +142,10 @@ Result:
field2: (string){ string }
}
foo: (_|_){
// [eval] foo: field `feild` not allowed
// [eval] foo: field `feild` not allowed:
// ./in.cue:1:1
// ./in.cue:1:7
// ./in.cue:13:6
field: (int){ int }
recursive: (#struct){
field: (string){ string }
Expand All @@ -147,7 +156,10 @@ Result:
// [eval]
field: (int){ 2 }
recursive: (_|_){
// [eval] foo1.recursive: field `feild` not allowed
// [eval] foo1.recursive: field `feild` not allowed:
// ./in.cue:1:1
// ./in.cue:3:13
// ./in.cue:18:13
field: (string){ string }
feild: (int){ 2 }
}
Expand Down

0 comments on commit cfc6c8c

Please sign in to comment.