this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

pkg/list: improve error message for MatchN

Show the expected value that we are matching against,
and simplify the wording.

Signed-off-by: Maximilian Gaß <m.gass@babiel.com>
Change-Id: Icf1b5ef965684c19ce94885ed0c0f2636a6a6964
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1234332
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

authored by

Maximilian Gaß and committed by
Daniel Martí
1b8f058b 9dd28f0a

+55 -41
+31 -23
cue/testdata/cycle/builtins.txtar
··· 361 361 jsonCycle.t1.x.y: invalid value "{}" (does not satisfy encoding/json.Validate): structural cycle: 362 362 ./jsoncycle.cue:4:8 363 363 ./jsoncycle.cue:5:8 364 - listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy 1: 364 + listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): {y:_|_(listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): value at path 'listMatchN.structCycle.x' matches 0 list items, want 1)} matches 0 list items, want 1: 365 365 ./listmatchncycle.cue:4:8 366 + ./listmatchncycle.cue:4:5 366 367 ./listmatchncycle.cue:4:20 368 + ./listmatchncycle.cue:5:5 367 369 ./listmatchncycle.cue:5:8 368 370 issue3443.matchIf.#S: cannot call non-function matchIf (type struct): 369 371 ./matchn.cue:16:7 ··· 649 651 x: (_|_){ 650 652 // [eval] 651 653 y: (_|_){ 652 - // [eval] listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy 1: 654 + // [eval] listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): {y:_|_(listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): value at path 'listMatchN.structCycle.x' matches 0 list items, want 1)} matches 0 list items, want 1: 653 655 // ./listmatchncycle.cue:4:8 656 + // ./listmatchncycle.cue:4:5 654 657 // ./listmatchncycle.cue:4:20 658 + // ./listmatchncycle.cue:5:5 655 659 // ./listmatchncycle.cue:5:8 656 660 0: (struct){ 657 661 } ··· 939 943 diff old new 940 944 --- old 941 945 +++ new 942 - @@ -1,26 +1,47 @@ 946 + @@ -1,26 +1,49 @@ 943 947 Errors: 944 948 +0: cannot use [_|_(0: cannot use value at path '_' (type list) as string in argument 1 to strconv.Atoi)] (type list) as string in argument 1 to strconv.Atoi: 945 949 + ./cycle.cue:39:24 ··· 984 988 +jsonCycle.t1.x.y: invalid value "{}" (does not satisfy encoding/json.Validate): structural cycle: 985 989 + ./jsoncycle.cue:4:8 986 990 + ./jsoncycle.cue:5:8 987 - +listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy 1: 991 + +listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): {y:_|_(listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): value at path 'listMatchN.structCycle.x' matches 0 list items, want 1)} matches 0 list items, want 1: 988 992 + ./listmatchncycle.cue:4:8 993 + + ./listmatchncycle.cue:4:5 989 994 + ./listmatchncycle.cue:4:20 995 + + ./listmatchncycle.cue:5:5 990 996 + ./listmatchncycle.cue:5:8 991 997 issue3443.matchIf.#S: cannot call non-function matchIf (type struct): 992 998 ./matchn.cue:16:7 ··· 1005 1011 issue3443.cycle2.fail.#S: invalid value {n:{n:{n:_}}} (does not satisfy matchN): 0 matched, expected 1: 1006 1012 ./matchn.cue:55:13 1007 1013 ./matchn.cue:55:20 1008 - @@ -53,26 +74,21 @@ 1014 + @@ -53,26 +76,21 @@ 1009 1015 ./yamlcycle.cue:15:8 1010 1016 selfCycle.t1.c.d.d.d: structural cycle: 1011 1017 ./yamlcycle.cue:14:5 ··· 1047 1053 1048 1054 Result: 1049 1055 (_|_){ 1050 - @@ -85,35 +101,30 @@ 1056 + @@ -85,35 +103,30 @@ 1051 1057 // [eval] 1052 1058 #x: (_|_){ 1053 1059 // [eval] noCycle.t1._s.#x: invalid value {} (does not satisfy matchN): 0 matched, expected 1: ··· 1103 1109 } 1104 1110 #c: (#struct){ 1105 1111 b?: (string){ string } 1106 - @@ -125,7 +136,6 @@ 1112 + @@ -125,7 +138,6 @@ 1107 1113 } 1108 1114 t2: (struct){ 1109 1115 x: (struct){ ··· 1111 1117 y: (struct){ 1112 1118 a: (struct){ 1113 1119 d: (struct){ 1114 - @@ -133,6 +143,7 @@ 1120 + @@ -133,6 +145,7 @@ 1115 1121 } 1116 1122 } 1117 1123 } ··· 1119 1125 } 1120 1126 c: (struct){ 1121 1127 b?: (string){ string } 1122 - @@ -147,13 +158,22 @@ 1128 + @@ -147,13 +160,22 @@ 1123 1129 } 1124 1130 } 1125 1131 } ··· 1149 1155 } 1150 1156 #c: (#struct){ 1151 1157 b: (string){ string } 1152 - @@ -165,6 +185,24 @@ 1158 + @@ -165,6 +187,24 @@ 1153 1159 } 1154 1160 } 1155 1161 } ··· 1174 1180 builtinCyclePerm0: (struct){ 1175 1181 X: (string){ "mod.test" } 1176 1182 Y: (struct){ 1177 - @@ -239,13 +277,31 @@ 1183 + @@ -239,13 +279,31 @@ 1178 1184 out: (int){ 1 } 1179 1185 } 1180 1186 } ··· 1208 1214 } 1209 1215 } 1210 1216 } 1211 - @@ -254,8 +310,15 @@ 1217 + @@ -254,8 +312,17 @@ 1212 1218 structCycle: (_|_){ 1213 1219 // [eval] 1214 1220 x: (_|_){ ··· 1216 1222 - // ./listmatchncycle.cue:4:23 1217 1223 + // [eval] 1218 1224 + y: (_|_){ 1219 - + // [eval] listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy 1: 1225 + + // [eval] listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): {y:_|_(listMatchN.structCycle.x.y: invalid value [{}] (does not satisfy list.MatchN): value at path 'listMatchN.structCycle.x' matches 0 list items, want 1)} matches 0 list items, want 1: 1220 1226 + // ./listmatchncycle.cue:4:8 1227 + + // ./listmatchncycle.cue:4:5 1221 1228 + // ./listmatchncycle.cue:4:20 1229 + + // ./listmatchncycle.cue:5:5 1222 1230 + // ./listmatchncycle.cue:5:8 1223 1231 + 0: (struct){ 1224 1232 + } ··· 1226 1234 } 1227 1235 } 1228 1236 ok: (struct){ 1229 - @@ -318,7 +381,7 @@ 1237 + @@ -318,7 +385,7 @@ 1230 1238 } 1231 1239 }) } 1232 1240 noHang: (struct){ ··· 1235 1243 n: (struct){ 1236 1244 n: (_){ _ } 1237 1245 } 1238 - @@ -333,7 +396,8 @@ 1246 + @@ -333,7 +400,8 @@ 1239 1247 } 1240 1248 }) } 1241 1249 } ··· 1245 1253 #S: (_){ matchN(1, (#list){ 1246 1254 0: (_|_){// { 1247 1255 // n: 〈2;#S〉 1248 - @@ -348,8 +412,21 @@ 1256 + @@ -348,8 +416,21 @@ 1249 1257 } 1250 1258 }) } 1251 1259 } ··· 1269 1277 n: (struct){ 1270 1278 n: (_){ _ } 1271 1279 } 1272 - @@ -393,13 +470,13 @@ 1280 + @@ -393,13 +474,13 @@ 1273 1281 // ./matchn.cue:63:6 1274 1282 // ./matchn.cue:62:8 1275 1283 // ./matchn.cue:63:13 ··· 1286 1294 } 1287 1295 #s: (_){ matchN(1, (#list){ 1288 1296 0: (_|_){// matchN(1, [ 1289 - @@ -411,6 +488,12 @@ 1297 + @@ -411,6 +492,12 @@ 1290 1298 }) } 1291 1299 } 1292 1300 } ··· 1299 1307 yamlNoCycle: (struct){ 1300 1308 #c: (#struct){ 1301 1309 b?: (string){ string } 1302 - @@ -417,8 +500,8 @@ 1310 + @@ -417,8 +504,8 @@ 1303 1311 a?: ((string|bytes)){ "encoding/yaml".Validate(yamlNoCycle.#c) } 1304 1312 } 1305 1313 data: (#struct){ ··· 1309 1317 } 1310 1318 } 1311 1319 selfCycle: (_|_){ 1312 - @@ -446,19 +529,8 @@ 1320 + @@ -446,19 +533,8 @@ 1313 1321 } 1314 1322 } 1315 1323 } ··· 1331 1339 } 1332 1340 } 1333 1341 yamlVal: (_|_){ 1334 - @@ -466,25 +538,33 @@ 1342 + @@ -466,25 +542,33 @@ 1335 1343 t1: (_|_){ 1336 1344 // [structural cycle] 1337 1345 x: (_|_){ ··· 1379 1387 } 1380 1388 } 1381 1389 t2: (_|_){ 1382 - @@ -492,13 +572,16 @@ 1390 + @@ -492,13 +576,16 @@ 1383 1391 z: (_|_){ 1384 1392 // [structural cycle] 1385 1393 y: (_|_){ ··· 1403 1411 } 1404 1412 } 1405 1413 } 1406 - @@ -505,8 +588,12 @@ 1414 + @@ -505,8 +592,12 @@ 1407 1415 yamlValidatePartial: (_|_){ 1408 1416 // [structural cycle] 1409 1417 x: (_|_){
+5 -3
pkg/list/list.go
··· 328 328 329 329 // matchN is the actual implementation of MatchN. 330 330 func matchN(c *adt.OpContext, list []cue.Value, n pkg.Schema, matchValue pkg.Schema) (bool, error) { 331 + matchVertex := value.Vertex(matchValue) 331 332 var nmatch int64 332 333 for _, w := range list { 333 - vx := adt.Unify(c, value.Vertex(matchValue), value.Vertex(w)) 334 + vx := adt.Unify(c, matchVertex, value.Vertex(w)) 334 335 x := value.Make(c, vx) 335 336 if x.Validate(cue.Final()) == nil { 336 337 nmatch++ ··· 342 343 if err := n.Unify(ctx.Encode(nmatch)).Err(); err != nil { 343 344 return false, pkg.ValidationError{B: &adt.Bottom{ 344 345 Code: adt.EvalError, 345 - Err: errors.Newf( 346 + Err: c.NewPosf( 346 347 token.NoPos, 347 - "number of matched elements is %d: does not satisfy %v", 348 + "%v matches %d list items, want %d", 349 + matchVertex, 348 350 nmatch, 349 351 n, 350 352 ),
+19 -15
pkg/list/testdata/matchn_err.txtar
··· 18 18 } 19 19 20 20 #TOO: {too: int} 21 - -- out/list -- 21 + -- out/list-v3 -- 22 22 Errors: 23 - t1.l1: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy >0: 23 + t1.l1: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): [string] matches 0 list items, want >0: 24 24 ./in.cue:6:6 25 25 ./in.cue:4:12 26 26 ./in.cue:6:18 27 - t1.l2: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 3: does not satisfy 1: 27 + ./in.cue:6:22 28 + t1.l2: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number matches 3 list items, want 1: 28 29 ./in.cue:7:6 29 30 ./in.cue:4:12 30 31 ./in.cue:7:18 31 32 ./in.cue:7:21 32 - t1.l3: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 1: does not satisfy >1: 33 + t1.l3: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): string matches 1 list items, want >1: 33 34 ./in.cue:8:6 34 35 ./in.cue:4:12 35 36 ./in.cue:8:18 36 37 ./in.cue:8:22 37 - t1.l4: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 3: does not satisfy 0: 38 + t1.l4: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number matches 3 list items, want 0: 38 39 ./in.cue:9:6 39 40 ./in.cue:4:12 40 41 ./in.cue:9:18 41 42 ./in.cue:9:21 42 - t1.l5: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 1: does not satisfy string: 43 + t1.l5: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): [int] matches 1 list items, want string: 43 44 ./in.cue:10:6 44 45 ./in.cue:4:12 45 46 ./in.cue:10:18 46 - t1.l6: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy >0: 47 + ./in.cue:10:26 48 + t1.l6: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): {too:int} matches 0 list items, want >0: 47 49 ./in.cue:11:6 48 50 ./in.cue:4:12 49 51 ./in.cue:11:18 50 - issue3519.a: invalid value [{}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy 1: 52 + ./in.cue:19:7 53 + issue3519.a: invalid value [{}] (does not satisfy list.MatchN): {a!:_} matches 0 list items, want 1: 51 54 ./in.cue:16:8 52 55 ./in.cue:15:8 53 56 ./in.cue:16:20 57 + ./in.cue:16:23 54 58 55 59 Result: 56 60 t1: { 57 - l1: _|_ // t1.l1: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy >0 58 - l2: _|_ // t1.l2: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 3: does not satisfy 1 59 - l3: _|_ // t1.l3: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 1: does not satisfy >1 60 - l4: _|_ // t1.l4: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 3: does not satisfy 0 61 - l5: _|_ // t1.l5: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 1: does not satisfy string 62 - l6: _|_ // t1.l6: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy >0 61 + l1: _|_ // t1.l1: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): t1.l1: [string] matches 0 list items, want >0 62 + l2: _|_ // t1.l2: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): t1.l2: number matches 3 list items, want 1 63 + l3: _|_ // t1.l3: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): t1.l3: string matches 1 list items, want >1 64 + l4: _|_ // t1.l4: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): t1.l4: number matches 3 list items, want 0 65 + l5: _|_ // t1.l5: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): t1.l5: [int] matches 1 list items, want string 66 + l6: _|_ // t1.l6: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): t1.l6: {too:int} matches 0 list items, want >0 63 67 } 64 68 issue3519: { 65 - a: _|_ // issue3519.a: invalid value [{}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy 1 69 + a: _|_ // issue3519.a: invalid value [{}] (does not satisfy list.MatchN): issue3519.a: {a!:_} matches 0 list items, want 1 66 70 } 67 71 #TOO: { 68 72 too: int