Skip to content

Commit

Permalink
internal/core/eval: centralize type checking
Browse files Browse the repository at this point in the history
This aims to make error checking more correct, easier
to manage and improve error messages.

Change-Id: I00bfd0742bb90549679eaa63894c30b1092a228d
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6702
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jul 25, 2020
1 parent 1dd08f3 commit d857f23
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 125 deletions.
4 changes: 2 additions & 2 deletions cue/testdata/basicrewrite/001_regexp.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ e3: _|_ // conflicting values !="a" and <5 (mismatched types string and number)
}
-- out/eval --
Errors:
e3: invalid value <5 (mismatched types number and string)
e3: conflicting values !="a" and <5 (mismatched types string and number)
b3: invalid value "foo" (out of bound =~"[a-z]{4}"):
./in.cue:10:5
e1: cannot use 1 (type int) as type (string|bytes):
Expand Down Expand Up @@ -95,6 +95,6 @@ Result:
// ./in.cue:19:5
}
e3: (_|_){
// [eval] e3: invalid value <5 (mismatched types number and string)
// [eval] e3: conflicting values !="a" and <5 (mismatched types string and number)
}
}
4 changes: 2 additions & 2 deletions cue/testdata/basicrewrite/006_basic_type.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ f: true
}
-- out/eval --
Errors:
d: invalid value float (mismatched types float and int)
d: conflicting values int and float (mismatched types int and float)

Result:
(_|_){
Expand All @@ -43,7 +43,7 @@ Result:
b: (int){ 1 }
c: (float){ 1.0 }
d: (_|_){
// [eval] d: invalid value float (mismatched types float and int)
// [eval] d: conflicting values int and float (mismatched types int and float)
}
e: (string){ "4" }
f: (bool){ true }
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/basicrewrite/010_lists.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ e5: [1, 2, 4, _|_, // invalid value 8 (out of bound <=5)
}
-- out/eval --
Errors:
e: conflicting types list and int
e: conflicting values 4 and [] (mismatched types int and list)
e2: invalid list index d (type string):
./in.cue:5:12
e3: invalid negative index -1:
Expand All @@ -101,7 +101,7 @@ Result:
2: (int){ 3 }
}
e: (_|_){
// [eval] e: conflicting types list and int
// [eval] e: conflicting values 4 and [] (mismatched types int and list)
}
e2: (_|_){
// [eval] e2: invalid list index d (type string):
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/basicrewrite/013_obj_unify.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ e: _|_ // conflicting values 1 and {a: 3} (mismatched types int and struct)
}
-- out/eval --
Errors:
e: conflicting values struct and int
e: conflicting values 1 and {a:3} (mismatched types int and struct)

Result:
(_|_){
Expand All @@ -97,7 +97,7 @@ Result:
b: (int){ 2 }
}
e: (_|_){
// [eval] e: conflicting values struct and int
// [eval] e: conflicting values 1 and {a:3} (mismatched types int and struct)
a: (int){ 3 }
}
}
16 changes: 8 additions & 8 deletions cue/testdata/basicrewrite/015_types.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ m: _|_ // invalid operation -false (- bool)
}
-- out/eval --
Errors:
e: invalid value string (mismatched types string and int)
e2: invalid value string (mismatched types string and int)
e: conflicting values int and string (mismatched types int and string)
e2: conflicting values 1 and string (mismatched types int and string)
b: value can never become concrete:
./in.cue:7:5
p: invalid operation ++true (+ bool):
p: invalid operation +true (+ bool):
./in.cue:8:5
m: invalid operation --false (- bool):
m: invalid operation -false (- bool):
./in.cue:9:5

Result:
Expand All @@ -56,21 +56,21 @@ Result:
s: (string){ string }
t: (string){ "s" }
e: (_|_){
// [eval] e: invalid value string (mismatched types string and int)
// [eval] e: conflicting values int and string (mismatched types int and string)
}
e2: (_|_){
// [eval] e2: invalid value string (mismatched types string and int)
// [eval] e2: conflicting values 1 and string (mismatched types int and string)
}
b: (_|_){
// [eval] b: value can never become concrete:
// ./in.cue:7:5
}
p: (_|_){
// [eval] p: invalid operation ++true (+ bool):
// [eval] p: invalid operation +true (+ bool):
// ./in.cue:8:5
}
m: (_|_){
// [eval] m: invalid operation --false (- bool):
// [eval] m: invalid operation -false (- bool):
// ./in.cue:9:5
}
}
45 changes: 26 additions & 19 deletions cue/testdata/cycle/structural.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Errors:
a1.f.0: structural cycle
a3.f.g: structural cycle
b4.x.y.0: structural cycle
b6.b.a.0: conflicting types list and int
b6.b.a.0: conflicting values 1 and [1] (mismatched types int and list)
b6.b.a.0.0: structural cycle
b6.x.a.0: structural cycle
b7.a.0: structural cycle
Expand All @@ -234,16 +234,18 @@ e1.a.c: structural cycle
e1.b.c: structural cycle
e2.a.c: structural cycle
e2.b.c: structural cycle
e3.a: conflicting types list and struct
e3.a.0: conflicting types list and struct
e3.a: conflicting values [a] and {c:a} (mismatched types list and struct)
e3.a.0: conflicting values [a] and {c:a} (mismatched types list and struct)
e3.a.0: structural cycle
e3.a.c: conflicting types list and struct
e3.a.c: conflicting values [a] and {c:a} (mismatched types list and struct)
e3.a.c: structural cycle
e3.b: conflicting types list and struct
e3.b.0: conflicting types list and struct
e3.b: conflicting values [b] and {c:b} (mismatched types list and struct)
e3.b.0: conflicting values [b] and {c:b} (mismatched types list and struct)
e3.b.0: structural cycle
e3.b.c: conflicting types list and struct
e3.b.c: conflicting values [b] and {c:b} (mismatched types list and struct)
e3.b.c: structural cycle
e4.a.0: conflicting values [{c:1}] and {} (mismatched types list and struct)
e4.b.0: conflicting values [{c:1}] and {} (mismatched types list and struct)
z1.z.f.h.h: structural cycle
z1.z.g.h: structural cycle
b4.x.y.0: structural cycle:
Expand Down Expand Up @@ -362,7 +364,7 @@ Result:
a: (_|_){
// [eval]
0: (_|_){
// [eval] b6.b.a.0: conflicting types list and int
// [eval] b6.b.a.0: conflicting values 1 and [1] (mismatched types int and list)
0: (_|_){
// [structural cycle] b6.b.a.0.0: structural cycle
}
Expand Down Expand Up @@ -570,17 +572,17 @@ Result:
e3: (_|_){
// [eval]
a: (_|_){
// [eval] e3.a: conflicting types list and struct
// [eval] e3.a: conflicting values [a] and {c:a} (mismatched types list and struct)
c: (_|_){
// [eval] e3.a.c: conflicting types list and struct
// [eval] e3.a.c: conflicting values [a] and {c:a} (mismatched types list and struct)
// e3.a.c: structural cycle
c: (_|_){// 〈1;a〉
}
0: (_|_){// 〈0;a〉
}
}
0: (_|_){
// [eval] e3.a.0: conflicting types list and struct
// [eval] e3.a.0: conflicting values [a] and {c:a} (mismatched types list and struct)
// e3.a.0: structural cycle
c: (_|_){// 〈1;a〉
}
Expand All @@ -589,17 +591,17 @@ Result:
}
}
b: (_|_){
// [eval] e3.b: conflicting types list and struct
// [eval] e3.b: conflicting values [b] and {c:b} (mismatched types list and struct)
c: (_|_){
// [eval] e3.b.c: conflicting types list and struct
// [eval] e3.b.c: conflicting values [b] and {c:b} (mismatched types list and struct)
// e3.b.c: structural cycle
c: (_|_){// 〈1;b〉
}
0: (_|_){// 〈0;b〉
}
}
0: (_|_){
// [eval] e3.b.0: conflicting types list and struct
// [eval] e3.b.0: conflicting values [b] and {c:b} (mismatched types list and struct)
// e3.b.0: structural cycle
c: (_|_){// 〈1;b〉
}
Expand All @@ -608,16 +610,21 @@ Result:
}
}
}
e4: (struct){
a: (#list){
0: (#list){
e4: (_|_){
// [eval]
a: (_|_){
// [eval]
0: (_|_){
// [eval] e4.a.0: conflicting values [{c:1}] and {} (mismatched types list and struct)
0: (struct){
c: (int){ 1 }
}
}
}
b: (#list){
0: (#list){
b: (_|_){
// [eval]
0: (_|_){
// [eval] e4.b.0: conflicting values [{c:1}] and {} (mismatched types list and struct)
0: (struct){
c: (int){ 1 }
}
Expand Down

0 comments on commit d857f23

Please sign in to comment.