fail_out_of_bound_not_literal.carbon 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. var a: (i32, i32) = (12, 34);
  7. // CHECK:STDERR: fail_out_of_bound_not_literal.carbon:[[@LINE+3]]:14: ERROR: Tuple element index `2` is past the end of type `(i32, i32)`.
  8. // CHECK:STDERR: var b: i32 = a[{.index = 2}.index];
  9. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  10. var b: i32 = a[{.index = 2}.index];
  11. // CHECK:STDOUT: --- fail_out_of_bound_not_literal.carbon
  12. // CHECK:STDOUT:
  13. // CHECK:STDOUT: constants {
  14. // CHECK:STDOUT: %.1: type = tuple_type (type, type) [template]
  15. // CHECK:STDOUT: %.2: type = tuple_type (i32, i32) [template]
  16. // CHECK:STDOUT: %.3: type = ptr_type (i32, i32) [template]
  17. // CHECK:STDOUT: %.4: i32 = int_literal 12 [template]
  18. // CHECK:STDOUT: %.5: i32 = int_literal 34 [template]
  19. // CHECK:STDOUT: %.6: (i32, i32) = tuple_value (%.4, %.5) [template]
  20. // CHECK:STDOUT: %.7: i32 = int_literal 2 [template]
  21. // CHECK:STDOUT: %.8: type = struct_type {.index: i32} [template]
  22. // CHECK:STDOUT: %.9: {.index: i32} = struct_value (%.7) [template]
  23. // CHECK:STDOUT: }
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: file {
  26. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  27. // CHECK:STDOUT: .a = %a
  28. // CHECK:STDOUT: .b = %b
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT: %.loc7_17.1: (type, type) = tuple_literal (i32, i32)
  31. // CHECK:STDOUT: %.loc7_17.2: type = converted %.loc7_17.1, constants.%.2 [template = constants.%.2]
  32. // CHECK:STDOUT: %a.var: ref (i32, i32) = var a
  33. // CHECK:STDOUT: %a: ref (i32, i32) = bind_name a, %a.var
  34. // CHECK:STDOUT: %b.var: ref i32 = var b
  35. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: fn @__global_init() {
  39. // CHECK:STDOUT: !entry:
  40. // CHECK:STDOUT: %.loc7_22: i32 = int_literal 12 [template = constants.%.4]
  41. // CHECK:STDOUT: %.loc7_26: i32 = int_literal 34 [template = constants.%.5]
  42. // CHECK:STDOUT: %.loc7_28.1: (i32, i32) = tuple_literal (%.loc7_22, %.loc7_26)
  43. // CHECK:STDOUT: %.loc7_28.2: ref i32 = tuple_access file.%a.var, element0
  44. // CHECK:STDOUT: %.loc7_28.3: init i32 = initialize_from %.loc7_22 to %.loc7_28.2 [template = constants.%.4]
  45. // CHECK:STDOUT: %.loc7_28.4: ref i32 = tuple_access file.%a.var, element1
  46. // CHECK:STDOUT: %.loc7_28.5: init i32 = initialize_from %.loc7_26 to %.loc7_28.4 [template = constants.%.5]
  47. // CHECK:STDOUT: %.loc7_28.6: init (i32, i32) = tuple_init (%.loc7_28.3, %.loc7_28.5) to file.%a.var [template = constants.%.6]
  48. // CHECK:STDOUT: %.loc7_28.7: init (i32, i32) = converted %.loc7_28.1, %.loc7_28.6 [template = constants.%.6]
  49. // CHECK:STDOUT: assign file.%a.var, %.loc7_28.7
  50. // CHECK:STDOUT: %a.ref: ref (i32, i32) = name_ref a, file.%a
  51. // CHECK:STDOUT: %.loc11_26: i32 = int_literal 2 [template = constants.%.7]
  52. // CHECK:STDOUT: %.loc11_27.1: {.index: i32} = struct_literal (%.loc11_26)
  53. // CHECK:STDOUT: %.loc11_27.2: {.index: i32} = struct_value (%.loc11_26) [template = constants.%.9]
  54. // CHECK:STDOUT: %.loc11_27.3: {.index: i32} = converted %.loc11_27.1, %.loc11_27.2 [template = constants.%.9]
  55. // CHECK:STDOUT: %.loc11_28: i32 = struct_access %.loc11_27.3, element0 [template = constants.%.7]
  56. // CHECK:STDOUT: %.loc11_34: ref <error> = tuple_index %a.ref, <error>
  57. // CHECK:STDOUT: assign file.%b.var, <error>
  58. // CHECK:STDOUT: return
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: