fail_aggregate.carbon 6.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/eval/fail_aggregate.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/eval/fail_aggregate.carbon
  10. // TODO: This creates an array temporary, which we don't yet support evaluating.
  11. // CHECK:STDERR: fail_aggregate.carbon:[[@LINE+3]]:43: ERROR: Array bound is not a constant.
  12. // CHECK:STDERR: var array_index: [i32; 1] = (0,) as [i32; ((5, 7, 1, 9) as [i32; 4])[2]];
  13. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. var array_index: [i32; 1] = (0,) as [i32; ((5, 7, 1, 9) as [i32; 4])[2]];
  15. // CHECK:STDOUT: --- fail_aggregate.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  19. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  20. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  21. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  22. // CHECK:STDOUT: %.3: type = array_type %.2, i32 [template]
  23. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  24. // CHECK:STDOUT: %.5: i32 = int_literal 0 [template]
  25. // CHECK:STDOUT: %.6: type = tuple_type (i32) [template]
  26. // CHECK:STDOUT: %.7: i32 = int_literal 5 [template]
  27. // CHECK:STDOUT: %.8: i32 = int_literal 7 [template]
  28. // CHECK:STDOUT: %.9: i32 = int_literal 9 [template]
  29. // CHECK:STDOUT: %.10: type = tuple_type (i32, i32, i32, i32) [template]
  30. // CHECK:STDOUT: %.11: i32 = int_literal 4 [template]
  31. // CHECK:STDOUT: %.12: type = array_type %.11, i32 [template]
  32. // CHECK:STDOUT: %.13: type = ptr_type %.12 [template]
  33. // CHECK:STDOUT: %.14: i32 = int_literal 2 [template]
  34. // CHECK:STDOUT: %.15: i32 = int_literal 3 [template]
  35. // CHECK:STDOUT: %array: %.12 = tuple_value (%.7, %.8, %.2, %.9) [template]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = %Core
  41. // CHECK:STDOUT: .array_index = %array_index
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  44. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  45. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  46. // CHECK:STDOUT: %.loc16_24: i32 = int_literal 1 [template = constants.%.2]
  47. // CHECK:STDOUT: %.loc16_19.1: type = value_of_initializer %int.make_type_32 [template = i32]
  48. // CHECK:STDOUT: %.loc16_19.2: type = converted %int.make_type_32, %.loc16_19.1 [template = i32]
  49. // CHECK:STDOUT: %.loc16_25: type = array_type %.loc16_24, i32 [template = constants.%.3]
  50. // CHECK:STDOUT: %array_index.var: ref %.3 = var array_index
  51. // CHECK:STDOUT: %array_index: ref %.3 = bind_name array_index, %array_index.var
  52. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  53. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: fn @__global_init() {
  59. // CHECK:STDOUT: !entry:
  60. // CHECK:STDOUT: %.loc16_30: i32 = int_literal 0 [template = constants.%.5]
  61. // CHECK:STDOUT: %.loc16_32: %.6 = tuple_literal (%.loc16_30)
  62. // CHECK:STDOUT: %int.make_type_32.loc16_38: init type = call constants.%Int32() [template = i32]
  63. // CHECK:STDOUT: %.loc16_45: i32 = int_literal 5 [template = constants.%.7]
  64. // CHECK:STDOUT: %.loc16_48: i32 = int_literal 7 [template = constants.%.8]
  65. // CHECK:STDOUT: %.loc16_51: i32 = int_literal 1 [template = constants.%.2]
  66. // CHECK:STDOUT: %.loc16_54: i32 = int_literal 9 [template = constants.%.9]
  67. // CHECK:STDOUT: %.loc16_55.1: %.10 = tuple_literal (%.loc16_45, %.loc16_48, %.loc16_51, %.loc16_54)
  68. // CHECK:STDOUT: %int.make_type_32.loc16_61: init type = call constants.%Int32() [template = i32]
  69. // CHECK:STDOUT: %.loc16_66: i32 = int_literal 4 [template = constants.%.11]
  70. // CHECK:STDOUT: %.loc16_61.1: type = value_of_initializer %int.make_type_32.loc16_61 [template = i32]
  71. // CHECK:STDOUT: %.loc16_61.2: type = converted %int.make_type_32.loc16_61, %.loc16_61.1 [template = i32]
  72. // CHECK:STDOUT: %.loc16_67: type = array_type %.loc16_66, i32 [template = constants.%.12]
  73. // CHECK:STDOUT: %.loc16_55.2: ref %.12 = temporary_storage
  74. // CHECK:STDOUT: %.loc16_55.3: i32 = int_literal 0 [template = constants.%.5]
  75. // CHECK:STDOUT: %.loc16_55.4: ref i32 = array_index %.loc16_55.2, %.loc16_55.3
  76. // CHECK:STDOUT: %.loc16_55.5: init i32 = initialize_from %.loc16_45 to %.loc16_55.4 [template = constants.%.7]
  77. // CHECK:STDOUT: %.loc16_55.6: i32 = int_literal 1 [template = constants.%.2]
  78. // CHECK:STDOUT: %.loc16_55.7: ref i32 = array_index %.loc16_55.2, %.loc16_55.6
  79. // CHECK:STDOUT: %.loc16_55.8: init i32 = initialize_from %.loc16_48 to %.loc16_55.7 [template = constants.%.8]
  80. // CHECK:STDOUT: %.loc16_55.9: i32 = int_literal 2 [template = constants.%.14]
  81. // CHECK:STDOUT: %.loc16_55.10: ref i32 = array_index %.loc16_55.2, %.loc16_55.9
  82. // CHECK:STDOUT: %.loc16_55.11: init i32 = initialize_from %.loc16_51 to %.loc16_55.10 [template = constants.%.2]
  83. // CHECK:STDOUT: %.loc16_55.12: i32 = int_literal 3 [template = constants.%.15]
  84. // CHECK:STDOUT: %.loc16_55.13: ref i32 = array_index %.loc16_55.2, %.loc16_55.12
  85. // CHECK:STDOUT: %.loc16_55.14: init i32 = initialize_from %.loc16_54 to %.loc16_55.13 [template = constants.%.9]
  86. // CHECK:STDOUT: %.loc16_55.15: init %.12 = array_init (%.loc16_55.5, %.loc16_55.8, %.loc16_55.11, %.loc16_55.14) to %.loc16_55.2 [template = constants.%array]
  87. // CHECK:STDOUT: %.loc16_57.1: init %.12 = converted %.loc16_55.1, %.loc16_55.15 [template = constants.%array]
  88. // CHECK:STDOUT: %.loc16_70: i32 = int_literal 2 [template = constants.%.14]
  89. // CHECK:STDOUT: %.loc16_57.2: ref %.12 = temporary %.loc16_55.2, %.loc16_57.1
  90. // CHECK:STDOUT: %.loc16_71.1: ref i32 = array_index %.loc16_57.2, %.loc16_70
  91. // CHECK:STDOUT: %.loc16_71.2: i32 = bind_value %.loc16_71.1
  92. // CHECK:STDOUT: assign file.%array_index.var, <error>
  93. // CHECK:STDOUT: return
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: