fail_aggregate.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 [InvalidArrayExpr]
  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: %.1: Core.IntLiteral = int_value 32 [template]
  19. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  20. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  21. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  22. // CHECK:STDOUT: %.2: Core.IntLiteral = int_value 1 [template]
  23. // CHECK:STDOUT: %.3: type = array_type %.2, %i32 [template]
  24. // CHECK:STDOUT: %.5: Core.IntLiteral = int_value 0 [template]
  25. // CHECK:STDOUT: %tuple.type.1: type = tuple_type (Core.IntLiteral) [template]
  26. // CHECK:STDOUT: %.6: Core.IntLiteral = int_value 5 [template]
  27. // CHECK:STDOUT: %.7: Core.IntLiteral = int_value 7 [template]
  28. // CHECK:STDOUT: %.8: Core.IntLiteral = int_value 9 [template]
  29. // CHECK:STDOUT: %tuple.type.2: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [template]
  30. // CHECK:STDOUT: %.9: Core.IntLiteral = int_value 4 [template]
  31. // CHECK:STDOUT: %.10: type = array_type %.9, %i32 [template]
  32. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  33. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  34. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  35. // CHECK:STDOUT: %.35: <witness> = interface_witness (%Convert.14) [template]
  36. // CHECK:STDOUT: %.36: <bound method> = bound_method %.6, %Convert.14 [template]
  37. // CHECK:STDOUT: %.37: <specific function> = specific_function %.36, @Convert.2(%.1) [template]
  38. // CHECK:STDOUT: %.38: %i32 = int_value 5 [template]
  39. // CHECK:STDOUT: %.39: <bound method> = bound_method %.7, %Convert.14 [template]
  40. // CHECK:STDOUT: %.40: <specific function> = specific_function %.39, @Convert.2(%.1) [template]
  41. // CHECK:STDOUT: %.41: %i32 = int_value 7 [template]
  42. // CHECK:STDOUT: %.42: Core.IntLiteral = int_value 2 [template]
  43. // CHECK:STDOUT: %.43: <bound method> = bound_method %.2, %Convert.14 [template]
  44. // CHECK:STDOUT: %.44: <specific function> = specific_function %.43, @Convert.2(%.1) [template]
  45. // CHECK:STDOUT: %.45: %i32 = int_value 1 [template]
  46. // CHECK:STDOUT: %.46: Core.IntLiteral = int_value 3 [template]
  47. // CHECK:STDOUT: %.47: <bound method> = bound_method %.8, %Convert.14 [template]
  48. // CHECK:STDOUT: %.48: <specific function> = specific_function %.47, @Convert.2(%.1) [template]
  49. // CHECK:STDOUT: %.49: %i32 = int_value 9 [template]
  50. // CHECK:STDOUT: %array: %.10 = tuple_value (%.38, %.41, %.45, %.49) [template]
  51. // CHECK:STDOUT: %.50: <bound method> = bound_method %.42, %Convert.14 [template]
  52. // CHECK:STDOUT: %.51: <specific function> = specific_function %.50, @Convert.2(%.1) [template]
  53. // CHECK:STDOUT: %.52: %i32 = int_value 2 [template]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: imports {
  57. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  58. // CHECK:STDOUT: .Int = %import_ref.1
  59. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  60. // CHECK:STDOUT: import Core//prelude
  61. // CHECK:STDOUT: import Core//prelude/...
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  67. // CHECK:STDOUT: .Core = imports.%Core
  68. // CHECK:STDOUT: .array_index = %array_index
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %Core.import = import Core
  71. // CHECK:STDOUT: %.loc16_19.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  72. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc16_19.1) [template = constants.%i32]
  73. // CHECK:STDOUT: %.loc16_24: Core.IntLiteral = int_value 1 [template = constants.%.2]
  74. // CHECK:STDOUT: %.loc16_19.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  75. // CHECK:STDOUT: %.loc16_19.3: type = converted %int.make_type_signed, %.loc16_19.2 [template = constants.%i32]
  76. // CHECK:STDOUT: %.loc16_25: type = array_type %.loc16_24, %i32 [template = constants.%.3]
  77. // CHECK:STDOUT: %array_index.var: ref %.3 = var array_index
  78. // CHECK:STDOUT: %array_index: ref %.3 = bind_name array_index, %array_index.var
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @__global_init() {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: %.loc16_30: Core.IntLiteral = int_value 0 [template = constants.%.5]
  84. // CHECK:STDOUT: %.loc16_32: %tuple.type.1 = tuple_literal (%.loc16_30)
  85. // CHECK:STDOUT: %.loc16_38.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  86. // CHECK:STDOUT: %int.make_type_signed.loc16_38: init type = call constants.%Int(%.loc16_38.1) [template = constants.%i32]
  87. // CHECK:STDOUT: %.loc16_45: Core.IntLiteral = int_value 5 [template = constants.%.6]
  88. // CHECK:STDOUT: %.loc16_48: Core.IntLiteral = int_value 7 [template = constants.%.7]
  89. // CHECK:STDOUT: %.loc16_51: Core.IntLiteral = int_value 1 [template = constants.%.2]
  90. // CHECK:STDOUT: %.loc16_54: Core.IntLiteral = int_value 9 [template = constants.%.8]
  91. // CHECK:STDOUT: %.loc16_55.1: %tuple.type.2 = tuple_literal (%.loc16_45, %.loc16_48, %.loc16_51, %.loc16_54)
  92. // CHECK:STDOUT: %.loc16_61.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  93. // CHECK:STDOUT: %int.make_type_signed.loc16_61: init type = call constants.%Int(%.loc16_61.1) [template = constants.%i32]
  94. // CHECK:STDOUT: %.loc16_66: Core.IntLiteral = int_value 4 [template = constants.%.9]
  95. // CHECK:STDOUT: %.loc16_61.2: type = value_of_initializer %int.make_type_signed.loc16_61 [template = constants.%i32]
  96. // CHECK:STDOUT: %.loc16_61.3: type = converted %int.make_type_signed.loc16_61, %.loc16_61.2 [template = constants.%i32]
  97. // CHECK:STDOUT: %.loc16_67: type = array_type %.loc16_66, %i32 [template = constants.%.10]
  98. // CHECK:STDOUT: %.loc16_55.2: %Convert.type.2 = interface_witness_access constants.%.35, element0 [template = constants.%Convert.14]
  99. // CHECK:STDOUT: %.loc16_55.3: <bound method> = bound_method %.loc16_45, %.loc16_55.2 [template = constants.%.36]
  100. // CHECK:STDOUT: %.loc16_55.4: <specific function> = specific_function %.loc16_55.3, @Convert.2(constants.%.1) [template = constants.%.37]
  101. // CHECK:STDOUT: %int.convert_checked.loc16_55.1: init %i32 = call %.loc16_55.4(%.loc16_45) [template = constants.%.38]
  102. // CHECK:STDOUT: %.loc16_55.5: init %i32 = converted %.loc16_45, %int.convert_checked.loc16_55.1 [template = constants.%.38]
  103. // CHECK:STDOUT: %.loc16_55.6: ref %.10 = temporary_storage
  104. // CHECK:STDOUT: %.loc16_55.7: Core.IntLiteral = int_value 0 [template = constants.%.5]
  105. // CHECK:STDOUT: %.loc16_55.8: ref %i32 = array_index %.loc16_55.6, %.loc16_55.7
  106. // CHECK:STDOUT: %.loc16_55.9: init %i32 = initialize_from %.loc16_55.5 to %.loc16_55.8 [template = constants.%.38]
  107. // CHECK:STDOUT: %.loc16_55.10: %Convert.type.2 = interface_witness_access constants.%.35, element0 [template = constants.%Convert.14]
  108. // CHECK:STDOUT: %.loc16_55.11: <bound method> = bound_method %.loc16_48, %.loc16_55.10 [template = constants.%.39]
  109. // CHECK:STDOUT: %.loc16_55.12: <specific function> = specific_function %.loc16_55.11, @Convert.2(constants.%.1) [template = constants.%.40]
  110. // CHECK:STDOUT: %int.convert_checked.loc16_55.2: init %i32 = call %.loc16_55.12(%.loc16_48) [template = constants.%.41]
  111. // CHECK:STDOUT: %.loc16_55.13: init %i32 = converted %.loc16_48, %int.convert_checked.loc16_55.2 [template = constants.%.41]
  112. // CHECK:STDOUT: %.loc16_55.14: Core.IntLiteral = int_value 1 [template = constants.%.2]
  113. // CHECK:STDOUT: %.loc16_55.15: ref %i32 = array_index %.loc16_55.6, %.loc16_55.14
  114. // CHECK:STDOUT: %.loc16_55.16: init %i32 = initialize_from %.loc16_55.13 to %.loc16_55.15 [template = constants.%.41]
  115. // CHECK:STDOUT: %.loc16_55.17: %Convert.type.2 = interface_witness_access constants.%.35, element0 [template = constants.%Convert.14]
  116. // CHECK:STDOUT: %.loc16_55.18: <bound method> = bound_method %.loc16_51, %.loc16_55.17 [template = constants.%.43]
  117. // CHECK:STDOUT: %.loc16_55.19: <specific function> = specific_function %.loc16_55.18, @Convert.2(constants.%.1) [template = constants.%.44]
  118. // CHECK:STDOUT: %int.convert_checked.loc16_55.3: init %i32 = call %.loc16_55.19(%.loc16_51) [template = constants.%.45]
  119. // CHECK:STDOUT: %.loc16_55.20: init %i32 = converted %.loc16_51, %int.convert_checked.loc16_55.3 [template = constants.%.45]
  120. // CHECK:STDOUT: %.loc16_55.21: Core.IntLiteral = int_value 2 [template = constants.%.42]
  121. // CHECK:STDOUT: %.loc16_55.22: ref %i32 = array_index %.loc16_55.6, %.loc16_55.21
  122. // CHECK:STDOUT: %.loc16_55.23: init %i32 = initialize_from %.loc16_55.20 to %.loc16_55.22 [template = constants.%.45]
  123. // CHECK:STDOUT: %.loc16_55.24: %Convert.type.2 = interface_witness_access constants.%.35, element0 [template = constants.%Convert.14]
  124. // CHECK:STDOUT: %.loc16_55.25: <bound method> = bound_method %.loc16_54, %.loc16_55.24 [template = constants.%.47]
  125. // CHECK:STDOUT: %.loc16_55.26: <specific function> = specific_function %.loc16_55.25, @Convert.2(constants.%.1) [template = constants.%.48]
  126. // CHECK:STDOUT: %int.convert_checked.loc16_55.4: init %i32 = call %.loc16_55.26(%.loc16_54) [template = constants.%.49]
  127. // CHECK:STDOUT: %.loc16_55.27: init %i32 = converted %.loc16_54, %int.convert_checked.loc16_55.4 [template = constants.%.49]
  128. // CHECK:STDOUT: %.loc16_55.28: Core.IntLiteral = int_value 3 [template = constants.%.46]
  129. // CHECK:STDOUT: %.loc16_55.29: ref %i32 = array_index %.loc16_55.6, %.loc16_55.28
  130. // CHECK:STDOUT: %.loc16_55.30: init %i32 = initialize_from %.loc16_55.27 to %.loc16_55.29 [template = constants.%.49]
  131. // CHECK:STDOUT: %.loc16_55.31: init %.10 = array_init (%.loc16_55.9, %.loc16_55.16, %.loc16_55.23, %.loc16_55.30) to %.loc16_55.6 [template = constants.%array]
  132. // CHECK:STDOUT: %.loc16_57.1: init %.10 = converted %.loc16_55.1, %.loc16_55.31 [template = constants.%array]
  133. // CHECK:STDOUT: %.loc16_70.1: Core.IntLiteral = int_value 2 [template = constants.%.42]
  134. // CHECK:STDOUT: %.loc16_57.2: ref %.10 = temporary %.loc16_55.6, %.loc16_57.1
  135. // CHECK:STDOUT: %.loc16_70.2: %Convert.type.2 = interface_witness_access constants.%.35, element0 [template = constants.%Convert.14]
  136. // CHECK:STDOUT: %.loc16_70.3: <bound method> = bound_method %.loc16_70.1, %.loc16_70.2 [template = constants.%.50]
  137. // CHECK:STDOUT: %.loc16_70.4: <specific function> = specific_function %.loc16_70.3, @Convert.2(constants.%.1) [template = constants.%.51]
  138. // CHECK:STDOUT: %int.convert_checked.loc16_70: init %i32 = call %.loc16_70.4(%.loc16_70.1) [template = constants.%.52]
  139. // CHECK:STDOUT: %.loc16_70.5: %i32 = value_of_initializer %int.convert_checked.loc16_70 [template = constants.%.52]
  140. // CHECK:STDOUT: %.loc16_70.6: %i32 = converted %.loc16_70.1, %.loc16_70.5 [template = constants.%.52]
  141. // CHECK:STDOUT: %.loc16_71.1: ref %i32 = array_index %.loc16_57.2, %.loc16_70.6
  142. // CHECK:STDOUT: %.loc16_71.2: %i32 = bind_value %.loc16_71.1
  143. // CHECK:STDOUT: %.loc16_38.2: type = value_of_initializer %int.make_type_signed.loc16_38 [template = constants.%i32]
  144. // CHECK:STDOUT: %.loc16_38.3: type = converted %int.make_type_signed.loc16_38, %.loc16_38.2 [template = constants.%i32]
  145. // CHECK:STDOUT: assign file.%array_index.var, <error>
  146. // CHECK:STDOUT: return
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT: