fail_out_of_bound.carbon 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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: %.2: type = array_type %.1, i32 [template]
  21. // CHECK:STDOUT: %.4: i32 = int_value 2 [template]
  22. // CHECK:STDOUT: %.5: i32 = int_value 3 [template]
  23. // CHECK:STDOUT: %tuple.type: type = tuple_type (i32, i32, i32) [template]
  24. // CHECK:STDOUT: }
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: imports {
  27. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  28. // CHECK:STDOUT: .Int32 = %import_ref
  29. // CHECK:STDOUT: import Core//prelude
  30. // CHECK:STDOUT: import Core//prelude/...
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: file {
  35. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  36. // CHECK:STDOUT: .Core = imports.%Core
  37. // CHECK:STDOUT: .a = %a
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %Core.import = import Core
  40. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  41. // CHECK:STDOUT: %.loc14_14: i32 = int_value 1 [template = constants.%.1]
  42. // CHECK:STDOUT: %.loc14_9.1: type = value_of_initializer %int.make_type_32 [template = i32]
  43. // CHECK:STDOUT: %.loc14_9.2: type = converted %int.make_type_32, %.loc14_9.1 [template = i32]
  44. // CHECK:STDOUT: %.loc14_15: type = array_type %.loc14_14, i32 [template = constants.%.2]
  45. // CHECK:STDOUT: %a.var: ref %.2 = var a
  46. // CHECK:STDOUT: %a: ref %.2 = bind_name a, %a.var
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: fn @__global_init() {
  50. // CHECK:STDOUT: !entry:
  51. // CHECK:STDOUT: %.loc14_20: i32 = int_value 1 [template = constants.%.1]
  52. // CHECK:STDOUT: %.loc14_23: i32 = int_value 2 [template = constants.%.4]
  53. // CHECK:STDOUT: %.loc14_26: i32 = int_value 3 [template = constants.%.5]
  54. // CHECK:STDOUT: %.loc14_27: %tuple.type = tuple_literal (%.loc14_20, %.loc14_23, %.loc14_26)
  55. // CHECK:STDOUT: assign file.%a.var, <error>
  56. // CHECK:STDOUT: return
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: