cuelang.org/go@v0.13.0/cue/testdata/resolve/016_index.txtar (about) 1 #name: index 2 #evalPartial 3 -- in.cue -- 4 a: [2][0] 5 b: {foo: "bar"}["foo"] 6 c: (*l | {"3": 3})["3"] 7 d: (*[] | [1])[0] 8 l: [] 9 e1: [2][""] 10 e2: 2[2] 11 e3: [][true] 12 e4: [1, 2, 3][3] 13 e5: [1, 2, 3][-1] 14 e6: (*[] | {})[1] 15 e7: [1, 2, 3][3] 16 e8: [1, 2, 3][-1] 17 e9: (*[] | {})[1] 18 19 def: { 20 a: 1 21 #b: 3 22 } 23 e7: def["b"] 24 -- out/def -- 25 a: 2 26 b: "bar" 27 c: _|_ // invalid list index "3" (type string) 28 l: [] 29 d: _|_ // index 0 out of bounds 30 e1: _|_ // invalid list index "" (type string) 31 e2: _|_ // invalid operation: 2[2] (type int does not support indexing) 32 e3: _|_ // invalid list index true (type bool) 33 e4: _|_ // index 3 out of bounds 34 e5: _|_ // invalid list index -1 (index must be non-negative) 35 e6: _|_ // index 1 out of bounds 36 def: { 37 a: 1 38 #b: 3 39 } 40 e7: def["b"] 41 -- out/legacy-debug -- 42 <0>{a: 2, b: "bar", c: _|_("3":invalid list index "3" (type string)), l: [], d: _|_([]:index 0 out of bounds), e1: _|_("":invalid list index "" (type string)), e2: _|_(2:invalid operation: 2[2] (type int does not support indexing)), e3: _|_(true:invalid list index true (type bool)), e4: _|_([1,2,3]:index 3 out of bounds), e5: _|_(-1:invalid list index -1 (index must be non-negative)), e6: _|_([]:index 1 out of bounds), def: <1>{a: 1, #b: 3}, e7: <2>.def["b"]} 43 -- out/compile -- 44 --- in.cue 45 { 46 a: [ 47 2, 48 ][0] 49 b: { 50 foo: "bar" 51 }["foo"] 52 c: (*〈0;l〉|{ 53 "3": 3 54 })["3"] 55 d: (*[]|[ 56 1, 57 ])[0] 58 l: [] 59 e1: [ 60 2, 61 ][""] 62 e2: 2[2] 63 e3: [][true] 64 e4: [ 65 1, 66 2, 67 3, 68 ][3] 69 e5: [ 70 1, 71 2, 72 3, 73 ][-1] 74 e6: (*[]|{})[1] 75 e7: [ 76 1, 77 2, 78 3, 79 ][3] 80 e8: [ 81 1, 82 2, 83 3, 84 ][-1] 85 e9: (*[]|{})[1] 86 def: { 87 a: 1 88 #b: 3 89 } 90 e7: 〈0;def〉["b"] 91 } 92 -- out/eval/stats -- 93 Leaks: 10 94 Freed: 32 95 Reused: 26 96 Allocs: 16 97 Retain: 12 98 99 Unifications: 34 100 Conjuncts: 44 101 Disjuncts: 42 102 -- out/evalalpha -- 103 Errors: 104 c: undefined field: "3": 105 ./in.cue:3:20 106 d: index out of range [0] with length 0: 107 ./in.cue:4:16 108 e1: undefined field: "": 109 ./in.cue:6:9 110 e2: invalid operand 2 (found int, want list or struct): 111 ./in.cue:7:5 112 e3: invalid index true (invalid type bool): 113 ./in.cue:8:5 114 ./in.cue:8:8 115 e4: index out of range [3] with length 3: 116 ./in.cue:9:15 117 e5: invalid index -1 (index must be non-negative): 118 ./in.cue:10:5 119 ./in.cue:10:15 120 e6: index out of range [1] with length 0: 121 ./in.cue:11:16 122 e7: index out of range [3] with length 3: 123 ./in.cue:12:15 124 e8: invalid index -1 (index must be non-negative): 125 ./in.cue:13:5 126 ./in.cue:13:15 127 e9: index out of range [1] with length 0: 128 ./in.cue:14:16 129 130 Result: 131 (_|_){ 132 // [eval] 133 a: (int){ 2 } 134 b: (string){ "bar" } 135 c: (_|_){ 136 // [eval] c: undefined field: "3": 137 // ./in.cue:3:20 138 } 139 d: (_|_){ 140 // [eval] d: index out of range [0] with length 0: 141 // ./in.cue:4:16 142 } 143 l: (#list){ 144 } 145 e1: (_|_){ 146 // [eval] e1: undefined field: "": 147 // ./in.cue:6:9 148 } 149 e2: (_|_){ 150 // [eval] e2: invalid operand 2 (found int, want list or struct): 151 // ./in.cue:7:5 152 } 153 e3: (_|_){ 154 // [eval] e3: invalid index true (invalid type bool): 155 // ./in.cue:8:5 156 // ./in.cue:8:8 157 } 158 e4: (_|_){ 159 // [eval] e4: index out of range [3] with length 3: 160 // ./in.cue:9:15 161 } 162 e5: (_|_){ 163 // [eval] e5: invalid index -1 (index must be non-negative): 164 // ./in.cue:10:5 165 // ./in.cue:10:15 166 } 167 e6: (_|_){ 168 // [eval] e6: index out of range [1] with length 0: 169 // ./in.cue:11:16 170 } 171 e7: (_|_){ 172 // [eval] e7: index out of range [3] with length 3: 173 // ./in.cue:12:15 174 } 175 e8: (_|_){ 176 // [eval] e8: invalid index -1 (index must be non-negative): 177 // ./in.cue:13:5 178 // ./in.cue:13:15 179 } 180 e9: (_|_){ 181 // [eval] e9: index out of range [1] with length 0: 182 // ./in.cue:14:16 183 } 184 def: (struct){ 185 a: (int){ 1 } 186 #b: (int){ 3 } 187 } 188 } 189 -- diff/-out/evalalpha<==>+out/eval -- 190 diff old new 191 --- old 192 +++ new 193 @@ -1,9 +1,9 @@ 194 Errors: 195 -c: invalid list index "3" (type string): 196 +c: undefined field: "3": 197 ./in.cue:3:20 198 d: index out of range [0] with length 0: 199 ./in.cue:4:16 200 -e1: invalid list index "" (type string): 201 +e1: undefined field: "": 202 ./in.cue:6:9 203 e2: invalid operand 2 (found int, want list or struct): 204 ./in.cue:7:5 205 @@ -15,7 +15,7 @@ 206 e5: invalid index -1 (index must be non-negative): 207 ./in.cue:10:5 208 ./in.cue:10:15 209 -e6: invalid list index 1 (out of bounds): 210 +e6: index out of range [1] with length 0: 211 ./in.cue:11:16 212 e7: index out of range [3] with length 3: 213 ./in.cue:12:15 214 @@ -22,7 +22,7 @@ 215 e8: invalid index -1 (index must be non-negative): 216 ./in.cue:13:5 217 ./in.cue:13:15 218 -e9: invalid list index 1 (out of bounds): 219 +e9: index out of range [1] with length 0: 220 ./in.cue:14:16 221 222 Result: 223 @@ -31,7 +31,7 @@ 224 a: (int){ 2 } 225 b: (string){ "bar" } 226 c: (_|_){ 227 - // [eval] c: invalid list index "3" (type string): 228 + // [eval] c: undefined field: "3": 229 // ./in.cue:3:20 230 } 231 d: (_|_){ 232 @@ -41,7 +41,7 @@ 233 l: (#list){ 234 } 235 e1: (_|_){ 236 - // [eval] e1: invalid list index "" (type string): 237 + // [eval] e1: undefined field: "": 238 // ./in.cue:6:9 239 } 240 e2: (_|_){ 241 @@ -63,7 +63,7 @@ 242 // ./in.cue:10:15 243 } 244 e6: (_|_){ 245 - // [eval] e6: invalid list index 1 (out of bounds): 246 + // [eval] e6: index out of range [1] with length 0: 247 // ./in.cue:11:16 248 } 249 e7: (_|_){ 250 @@ -76,7 +76,7 @@ 251 // ./in.cue:13:15 252 } 253 e9: (_|_){ 254 - // [eval] e9: invalid list index 1 (out of bounds): 255 + // [eval] e9: index out of range [1] with length 0: 256 // ./in.cue:14:16 257 } 258 def: (struct){ 259 -- diff/todo/p3 -- 260 Error messages slightly different. 261 -- out/eval -- 262 Errors: 263 c: invalid list index "3" (type string): 264 ./in.cue:3:20 265 d: index out of range [0] with length 0: 266 ./in.cue:4:16 267 e1: invalid list index "" (type string): 268 ./in.cue:6:9 269 e2: invalid operand 2 (found int, want list or struct): 270 ./in.cue:7:5 271 e3: invalid index true (invalid type bool): 272 ./in.cue:8:5 273 ./in.cue:8:8 274 e4: index out of range [3] with length 3: 275 ./in.cue:9:15 276 e5: invalid index -1 (index must be non-negative): 277 ./in.cue:10:5 278 ./in.cue:10:15 279 e6: invalid list index 1 (out of bounds): 280 ./in.cue:11:16 281 e7: index out of range [3] with length 3: 282 ./in.cue:12:15 283 e8: invalid index -1 (index must be non-negative): 284 ./in.cue:13:5 285 ./in.cue:13:15 286 e9: invalid list index 1 (out of bounds): 287 ./in.cue:14:16 288 289 Result: 290 (_|_){ 291 // [eval] 292 a: (int){ 2 } 293 b: (string){ "bar" } 294 c: (_|_){ 295 // [eval] c: invalid list index "3" (type string): 296 // ./in.cue:3:20 297 } 298 d: (_|_){ 299 // [eval] d: index out of range [0] with length 0: 300 // ./in.cue:4:16 301 } 302 l: (#list){ 303 } 304 e1: (_|_){ 305 // [eval] e1: invalid list index "" (type string): 306 // ./in.cue:6:9 307 } 308 e2: (_|_){ 309 // [eval] e2: invalid operand 2 (found int, want list or struct): 310 // ./in.cue:7:5 311 } 312 e3: (_|_){ 313 // [eval] e3: invalid index true (invalid type bool): 314 // ./in.cue:8:5 315 // ./in.cue:8:8 316 } 317 e4: (_|_){ 318 // [eval] e4: index out of range [3] with length 3: 319 // ./in.cue:9:15 320 } 321 e5: (_|_){ 322 // [eval] e5: invalid index -1 (index must be non-negative): 323 // ./in.cue:10:5 324 // ./in.cue:10:15 325 } 326 e6: (_|_){ 327 // [eval] e6: invalid list index 1 (out of bounds): 328 // ./in.cue:11:16 329 } 330 e7: (_|_){ 331 // [eval] e7: index out of range [3] with length 3: 332 // ./in.cue:12:15 333 } 334 e8: (_|_){ 335 // [eval] e8: invalid index -1 (index must be non-negative): 336 // ./in.cue:13:5 337 // ./in.cue:13:15 338 } 339 e9: (_|_){ 340 // [eval] e9: invalid list index 1 (out of bounds): 341 // ./in.cue:14:16 342 } 343 def: (struct){ 344 a: (int){ 1 } 345 #b: (int){ 3 } 346 } 347 }