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