fail_out_of_bound.carbon 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/array/fail_out_of_bound.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/fail_out_of_bound.carbon
  10. // CHECK:STDERR: fail_out_of_bound.carbon:[[@LINE+3]]:19: error: cannot initialize array of 1 element from 3 initializers [ArrayInitFromLiteralArgCountMismatch]
  11. // CHECK:STDERR: var a: [i32; 1] = (1, 2, 3);
  12. // CHECK:STDERR: ^~~~~~~~~
  13. var a: [i32; 1] = (1, 2, 3);
  14. // CHECK:STDOUT: --- fail_out_of_bound.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  18. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  19. // CHECK:STDOUT: %.1: i32 = int_value 1 [template]
  20. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(Core.IntLiteral) [template]
  21. // CHECK:STDOUT: %Convert.type.15: type = fn_type @Convert.11 [template]
  22. // CHECK:STDOUT: %Convert.15: %Convert.type.15 = struct_value () [template]
  23. // CHECK:STDOUT: %.25: <witness> = interface_witness (%Convert.15) [template]
  24. // CHECK:STDOUT: %.26: <bound method> = bound_method %.1, %Convert.15 [template]
  25. // CHECK:STDOUT: %.27: Core.IntLiteral = int_value 1 [template]
  26. // CHECK:STDOUT: %.28: type = array_type %.27, i32 [template]
  27. // CHECK:STDOUT: %.30: i32 = int_value 2 [template]
  28. // CHECK:STDOUT: %.31: i32 = int_value 3 [template]
  29. // CHECK:STDOUT: %tuple.type: type = tuple_type (i32, i32, i32) [template]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: imports {
  33. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  34. // CHECK:STDOUT: .Int32 = %import_ref.1
  35. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/...
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  43. // CHECK:STDOUT: .Core = imports.%Core
  44. // CHECK:STDOUT: .a = %a
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %Core.import = import Core
  47. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  48. // CHECK:STDOUT: %.loc14_14.1: i32 = int_value 1 [template = constants.%.1]
  49. // CHECK:STDOUT: %.loc14_9.1: type = value_of_initializer %int.make_type_32 [template = i32]
  50. // CHECK:STDOUT: %.loc14_9.2: type = converted %int.make_type_32, %.loc14_9.1 [template = i32]
  51. // CHECK:STDOUT: %.loc14_14.2: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.15]
  52. // CHECK:STDOUT: %.loc14_14.3: <bound method> = bound_method %.loc14_14.1, %.loc14_14.2 [template = constants.%.26]
  53. // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %.loc14_14.3(%.loc14_14.1) [template = constants.%.27]
  54. // CHECK:STDOUT: %.loc14_14.4: Core.IntLiteral = value_of_initializer %int.convert_checked [template = constants.%.27]
  55. // CHECK:STDOUT: %.loc14_14.5: Core.IntLiteral = converted %.loc14_14.1, %.loc14_14.4 [template = constants.%.27]
  56. // CHECK:STDOUT: %.loc14_15: type = array_type %.loc14_14.5, i32 [template = constants.%.28]
  57. // CHECK:STDOUT: %a.var: ref %.28 = var a
  58. // CHECK:STDOUT: %a: ref %.28 = bind_name a, %a.var
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: fn @__global_init() {
  62. // CHECK:STDOUT: !entry:
  63. // CHECK:STDOUT: %.loc14_20: i32 = int_value 1 [template = constants.%.1]
  64. // CHECK:STDOUT: %.loc14_23: i32 = int_value 2 [template = constants.%.30]
  65. // CHECK:STDOUT: %.loc14_26: i32 = int_value 3 [template = constants.%.31]
  66. // CHECK:STDOUT: %.loc14_27: %tuple.type = tuple_literal (%.loc14_20, %.loc14_23, %.loc14_26)
  67. // CHECK:STDOUT: assign file.%a.var, <error>
  68. // CHECK:STDOUT: return
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: