| -- in.cue -- |
| intIndex: [2][0] |
| stringIndex: {foo: "bar"}["foo"] |
| |
| stringOfNumberIndex: {"3": 3}["3"] |
| |
| indexToDefault: (*[0] | {})[0] |
| outOfBoundsDisjunction: (*[] | {})[1] |
| |
| // Ensure these are errors. |
| indexDoesNotDistribute: (*[] | [1])[0] |
| doesNotDistributeType: { |
| l: [] |
| a: (*l | {"3": 3})["3"] |
| } |
| |
| stringIndexToList: [2][""] |
| indexOutOfBounds2: 2[2] |
| booleanIndex: [][true] |
| indexOutOfBounds3: [1, 2, 3][4] |
| negativeIndex: [1, 2, 3][-1] |
| |
| varIndexTooLarge: { |
| n: 3 |
| a: [1, 2, 3][n] |
| } |
| |
| varNegativeIndex: { |
| n: -1 |
| a: [1, 2, 3][n] |
| } |
| -- out/eval -- |
| Errors: |
| outOfBoundsDisjunction: invalid list index 1 (out of bounds): |
| ./in.cue:7:36 |
| indexDoesNotDistribute: index out of range [0] with length 0: |
| ./in.cue:10:41 |
| doesNotDistributeType.a: invalid list index "3" (type string): |
| ./in.cue:13:24 |
| stringIndexToList: invalid list index "" (type string): |
| ./in.cue:16:24 |
| indexOutOfBounds2: invalid operand 2 (found int, want list or struct): |
| ./in.cue:17:20 |
| booleanIndex: invalid index true (invalid type bool): |
| ./in.cue:18:15 |
| ./in.cue:18:18 |
| indexOutOfBounds3: invalid list index 4 (out of bounds): |
| ./in.cue:19:30 |
| negativeIndex: invalid index -1 (index must be non-negative): |
| ./in.cue:20:16 |
| ./in.cue:20:26 |
| varIndexTooLarge.a: index out of range [3] with length 3: |
| ./in.cue:24:18 |
| varNegativeIndex.a: index n out of range [-1]: |
| ./in.cue:29:8 |
| ./in.cue:28:8 |
| ./in.cue:29:18 |
| |
| Result: |
| (_|_){ |
| // [eval] |
| intIndex: (int){ 2 } |
| stringIndex: (string){ "bar" } |
| stringOfNumberIndex: (int){ 3 } |
| indexToDefault: (int){ 0 } |
| outOfBoundsDisjunction: (_|_){ |
| // [eval] outOfBoundsDisjunction: invalid list index 1 (out of bounds): |
| // ./in.cue:7:36 |
| } |
| indexDoesNotDistribute: (_|_){ |
| // [eval] indexDoesNotDistribute: index out of range [0] with length 0: |
| // ./in.cue:10:41 |
| } |
| doesNotDistributeType: (_|_){ |
| // [eval] |
| l: (#list){ |
| } |
| a: (_|_){ |
| // [eval] doesNotDistributeType.a: invalid list index "3" (type string): |
| // ./in.cue:13:24 |
| } |
| } |
| stringIndexToList: (_|_){ |
| // [eval] stringIndexToList: invalid list index "" (type string): |
| // ./in.cue:16:24 |
| } |
| indexOutOfBounds2: (_|_){ |
| // [eval] indexOutOfBounds2: invalid operand 2 (found int, want list or struct): |
| // ./in.cue:17:20 |
| } |
| booleanIndex: (_|_){ |
| // [eval] booleanIndex: invalid index true (invalid type bool): |
| // ./in.cue:18:15 |
| // ./in.cue:18:18 |
| } |
| indexOutOfBounds3: (_|_){ |
| // [eval] indexOutOfBounds3: invalid list index 4 (out of bounds): |
| // ./in.cue:19:30 |
| } |
| negativeIndex: (_|_){ |
| // [eval] negativeIndex: invalid index -1 (index must be non-negative): |
| // ./in.cue:20:16 |
| // ./in.cue:20:26 |
| } |
| varIndexTooLarge: (_|_){ |
| // [eval] |
| n: (int){ 3 } |
| a: (_|_){ |
| // [eval] varIndexTooLarge.a: index out of range [3] with length 3: |
| // ./in.cue:24:18 |
| } |
| } |
| varNegativeIndex: (_|_){ |
| // [eval] |
| n: (int){ -1 } |
| a: (_|_){ |
| // [eval] varNegativeIndex.a: index n out of range [-1]: |
| // ./in.cue:29:8 |
| // ./in.cue:28:8 |
| // ./in.cue:29:18 |
| } |
| } |
| } |
| -- out/compile -- |
| --- in.cue |
| { |
| intIndex: [ |
| 2, |
| ][0] |
| stringIndex: { |
| foo: "bar" |
| }["foo"] |
| stringOfNumberIndex: { |
| "3": 3 |
| }["3"] |
| indexToDefault: (*[ |
| 0, |
| ]|{})[0] |
| outOfBoundsDisjunction: (*[]|{})[1] |
| indexDoesNotDistribute: (*[]|[ |
| 1, |
| ])[0] |
| doesNotDistributeType: { |
| l: [] |
| a: (*〈0;l〉|{ |
| "3": 3 |
| })["3"] |
| } |
| stringIndexToList: [ |
| 2, |
| ][""] |
| indexOutOfBounds2: 2[2] |
| booleanIndex: [][true] |
| indexOutOfBounds3: [ |
| 1, |
| 2, |
| 3, |
| ][4] |
| negativeIndex: [ |
| 1, |
| 2, |
| 3, |
| ][-1] |
| varIndexTooLarge: { |
| n: 3 |
| a: [ |
| 1, |
| 2, |
| 3, |
| ][〈0;n〉] |
| } |
| varNegativeIndex: { |
| n: -1 |
| a: [ |
| 1, |
| 2, |
| 3, |
| ][〈0;n〉] |
| } |
| } |