fail_aggregate.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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+4]]:43: error: array bound is not a constant [InvalidArrayExpr]
  12. // CHECK:STDERR: var array_index: [i32; 1] = (0,) as [i32; ((5, 7, 1, 9) as [i32; 4])[2]];
  13. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. // CHECK:STDERR:
  15. var array_index: [i32; 1] = (0,) as [i32; ((5, 7, 1, 9) as [i32; 4])[2]];
  16. // CHECK:STDOUT: --- fail_aggregate.carbon
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: constants {
  19. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  20. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  21. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
  22. // CHECK:STDOUT: %array_type.0cb: type = array_type %int_1.5b8, %i32 [template]
  23. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
  24. // CHECK:STDOUT: %tuple.type.985: type = tuple_type (Core.IntLiteral) [template]
  25. // CHECK:STDOUT: %int_5.64b: Core.IntLiteral = int_value 5 [template]
  26. // CHECK:STDOUT: %int_7.29f: Core.IntLiteral = int_value 7 [template]
  27. // CHECK:STDOUT: %int_9.988: Core.IntLiteral = int_value 9 [template]
  28. // CHECK:STDOUT: %tuple.type.d46: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [template]
  29. // CHECK:STDOUT: %int_4: Core.IntLiteral = int_value 4 [template]
  30. // CHECK:STDOUT: %array_type.f32: type = array_type %int_4, %i32 [template]
  31. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [template]
  32. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  33. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template]
  34. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  35. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  36. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [template]
  37. // CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [template]
  38. // CHECK:STDOUT: %Convert.bound.4e6: <bound method> = bound_method %int_5.64b, %Convert.956 [template]
  39. // CHECK:STDOUT: %Convert.specific_fn.ba9: <specific function> = specific_function %Convert.bound.4e6, @Convert.2(%int_32) [template]
  40. // CHECK:STDOUT: %int_5.0f6: %i32 = int_value 5 [template]
  41. // CHECK:STDOUT: %Convert.bound.208: <bound method> = bound_method %int_7.29f, %Convert.956 [template]
  42. // CHECK:STDOUT: %Convert.specific_fn.c12: <specific function> = specific_function %Convert.bound.208, @Convert.2(%int_32) [template]
  43. // CHECK:STDOUT: %int_7.0b1: %i32 = int_value 7 [template]
  44. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [template]
  45. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [template]
  46. // CHECK:STDOUT: %Convert.specific_fn.70c: <specific function> = specific_function %Convert.bound.ab5, @Convert.2(%int_32) [template]
  47. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [template]
  48. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template]
  49. // CHECK:STDOUT: %Convert.bound.9e2: <bound method> = bound_method %int_9.988, %Convert.956 [template]
  50. // CHECK:STDOUT: %Convert.specific_fn.b02: <specific function> = specific_function %Convert.bound.9e2, @Convert.2(%int_32) [template]
  51. // CHECK:STDOUT: %int_9.f88: %i32 = int_value 9 [template]
  52. // CHECK:STDOUT: %array: %array_type.f32 = tuple_value (%int_5.0f6, %int_7.0b1, %int_1.5d2, %int_9.f88) [template]
  53. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [template]
  54. // CHECK:STDOUT: %Convert.specific_fn.787: <specific function> = specific_function %Convert.bound.ef9, @Convert.2(%int_32) [template]
  55. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [template]
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: imports {
  59. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  60. // CHECK:STDOUT: .Int = %Core.Int
  61. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  62. // CHECK:STDOUT: import Core//prelude
  63. // CHECK:STDOUT: import Core//prelude/...
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: file {
  68. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  69. // CHECK:STDOUT: .Core = imports.%Core
  70. // CHECK:STDOUT: .array_index = %array_index
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Core.import = import Core
  73. // CHECK:STDOUT: name_binding_decl {
  74. // CHECK:STDOUT: %array_index.patt: %array_type.0cb = binding_pattern array_index
  75. // CHECK:STDOUT: %.loc17_1: %array_type.0cb = var_pattern %array_index.patt
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %array_index.var: ref %array_type.0cb = var array_index
  78. // CHECK:STDOUT: %.loc17_25: type = splice_block %array_type [template = constants.%array_type.0cb] {
  79. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  80. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  81. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  82. // CHECK:STDOUT: %array_type: type = array_type %int_1, %i32 [template = constants.%array_type.0cb]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %array_index: ref %array_type.0cb = bind_name array_index, %array_index.var
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: fn @__global_init() {
  88. // CHECK:STDOUT: !entry:
  89. // CHECK:STDOUT: %int_0.loc17_30: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  90. // CHECK:STDOUT: %.loc17_32: %tuple.type.985 = tuple_literal (%int_0.loc17_30)
  91. // CHECK:STDOUT: %int_32.loc17_38: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  92. // CHECK:STDOUT: %i32.loc17_38: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  93. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [template = constants.%int_5.64b]
  94. // CHECK:STDOUT: %int_7: Core.IntLiteral = int_value 7 [template = constants.%int_7.29f]
  95. // CHECK:STDOUT: %int_1.loc17_51: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  96. // CHECK:STDOUT: %int_9: Core.IntLiteral = int_value 9 [template = constants.%int_9.988]
  97. // CHECK:STDOUT: %.loc17_55.1: %tuple.type.d46 = tuple_literal (%int_5, %int_7, %int_1.loc17_51, %int_9)
  98. // CHECK:STDOUT: %int_32.loc17_61: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  99. // CHECK:STDOUT: %i32.loc17_61: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  100. // CHECK:STDOUT: %int_4: Core.IntLiteral = int_value 4 [template = constants.%int_4]
  101. // CHECK:STDOUT: %array_type: type = array_type %int_4, %i32 [template = constants.%array_type.f32]
  102. // CHECK:STDOUT: %impl.elem0.loc17_55.1: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  103. // CHECK:STDOUT: %bound_method.loc17_55.1: <bound method> = bound_method %int_5, %impl.elem0.loc17_55.1 [template = constants.%Convert.bound.4e6]
  104. // CHECK:STDOUT: %specific_fn.loc17_55.1: <specific function> = specific_function %bound_method.loc17_55.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.ba9]
  105. // CHECK:STDOUT: %int.convert_checked.loc17_55.1: init %i32 = call %specific_fn.loc17_55.1(%int_5) [template = constants.%int_5.0f6]
  106. // CHECK:STDOUT: %.loc17_55.2: init %i32 = converted %int_5, %int.convert_checked.loc17_55.1 [template = constants.%int_5.0f6]
  107. // CHECK:STDOUT: %.loc17_55.3: ref %array_type.f32 = temporary_storage
  108. // CHECK:STDOUT: %int_0.loc17_55: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  109. // CHECK:STDOUT: %.loc17_55.4: ref %i32 = array_index %.loc17_55.3, %int_0.loc17_55
  110. // CHECK:STDOUT: %.loc17_55.5: init %i32 = initialize_from %.loc17_55.2 to %.loc17_55.4 [template = constants.%int_5.0f6]
  111. // CHECK:STDOUT: %impl.elem0.loc17_55.2: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  112. // CHECK:STDOUT: %bound_method.loc17_55.2: <bound method> = bound_method %int_7, %impl.elem0.loc17_55.2 [template = constants.%Convert.bound.208]
  113. // CHECK:STDOUT: %specific_fn.loc17_55.2: <specific function> = specific_function %bound_method.loc17_55.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.c12]
  114. // CHECK:STDOUT: %int.convert_checked.loc17_55.2: init %i32 = call %specific_fn.loc17_55.2(%int_7) [template = constants.%int_7.0b1]
  115. // CHECK:STDOUT: %.loc17_55.6: init %i32 = converted %int_7, %int.convert_checked.loc17_55.2 [template = constants.%int_7.0b1]
  116. // CHECK:STDOUT: %int_1.loc17_55: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  117. // CHECK:STDOUT: %.loc17_55.7: ref %i32 = array_index %.loc17_55.3, %int_1.loc17_55
  118. // CHECK:STDOUT: %.loc17_55.8: init %i32 = initialize_from %.loc17_55.6 to %.loc17_55.7 [template = constants.%int_7.0b1]
  119. // CHECK:STDOUT: %impl.elem0.loc17_55.3: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  120. // CHECK:STDOUT: %bound_method.loc17_55.3: <bound method> = bound_method %int_1.loc17_51, %impl.elem0.loc17_55.3 [template = constants.%Convert.bound.ab5]
  121. // CHECK:STDOUT: %specific_fn.loc17_55.3: <specific function> = specific_function %bound_method.loc17_55.3, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
  122. // CHECK:STDOUT: %int.convert_checked.loc17_55.3: init %i32 = call %specific_fn.loc17_55.3(%int_1.loc17_51) [template = constants.%int_1.5d2]
  123. // CHECK:STDOUT: %.loc17_55.9: init %i32 = converted %int_1.loc17_51, %int.convert_checked.loc17_55.3 [template = constants.%int_1.5d2]
  124. // CHECK:STDOUT: %int_2.loc17_55: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  125. // CHECK:STDOUT: %.loc17_55.10: ref %i32 = array_index %.loc17_55.3, %int_2.loc17_55
  126. // CHECK:STDOUT: %.loc17_55.11: init %i32 = initialize_from %.loc17_55.9 to %.loc17_55.10 [template = constants.%int_1.5d2]
  127. // CHECK:STDOUT: %impl.elem0.loc17_55.4: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  128. // CHECK:STDOUT: %bound_method.loc17_55.4: <bound method> = bound_method %int_9, %impl.elem0.loc17_55.4 [template = constants.%Convert.bound.9e2]
  129. // CHECK:STDOUT: %specific_fn.loc17_55.4: <specific function> = specific_function %bound_method.loc17_55.4, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.b02]
  130. // CHECK:STDOUT: %int.convert_checked.loc17_55.4: init %i32 = call %specific_fn.loc17_55.4(%int_9) [template = constants.%int_9.f88]
  131. // CHECK:STDOUT: %.loc17_55.12: init %i32 = converted %int_9, %int.convert_checked.loc17_55.4 [template = constants.%int_9.f88]
  132. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template = constants.%int_3]
  133. // CHECK:STDOUT: %.loc17_55.13: ref %i32 = array_index %.loc17_55.3, %int_3
  134. // CHECK:STDOUT: %.loc17_55.14: init %i32 = initialize_from %.loc17_55.12 to %.loc17_55.13 [template = constants.%int_9.f88]
  135. // CHECK:STDOUT: %.loc17_55.15: init %array_type.f32 = array_init (%.loc17_55.5, %.loc17_55.8, %.loc17_55.11, %.loc17_55.14) to %.loc17_55.3 [template = constants.%array]
  136. // CHECK:STDOUT: %.loc17_57.1: init %array_type.f32 = converted %.loc17_55.1, %.loc17_55.15 [template = constants.%array]
  137. // CHECK:STDOUT: %int_2.loc17_70: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  138. // CHECK:STDOUT: %.loc17_57.2: ref %array_type.f32 = temporary %.loc17_55.3, %.loc17_57.1
  139. // CHECK:STDOUT: %int_32.loc17_71: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  140. // CHECK:STDOUT: %i32.loc17_71: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  141. // CHECK:STDOUT: %impl.elem0.loc17_70: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  142. // CHECK:STDOUT: %bound_method.loc17_70: <bound method> = bound_method %int_2.loc17_70, %impl.elem0.loc17_70 [template = constants.%Convert.bound.ef9]
  143. // CHECK:STDOUT: %specific_fn.loc17_70: <specific function> = specific_function %bound_method.loc17_70, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.787]
  144. // CHECK:STDOUT: %int.convert_checked.loc17_70: init %i32 = call %specific_fn.loc17_70(%int_2.loc17_70) [template = constants.%int_2.ef8]
  145. // CHECK:STDOUT: %.loc17_70.1: %i32 = value_of_initializer %int.convert_checked.loc17_70 [template = constants.%int_2.ef8]
  146. // CHECK:STDOUT: %.loc17_70.2: %i32 = converted %int_2.loc17_70, %.loc17_70.1 [template = constants.%int_2.ef8]
  147. // CHECK:STDOUT: %.loc17_71.1: ref %i32 = array_index %.loc17_57.2, %.loc17_70.2
  148. // CHECK:STDOUT: %.loc17_71.2: %i32 = bind_value %.loc17_71.1
  149. // CHECK:STDOUT: assign file.%array_index.var, <error>
  150. // CHECK:STDOUT: return
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: