fail_out_of_bound.carbon 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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+4]]: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. // CHECK:STDERR:
  14. var a: [i32; 1] = (1, 2, 3);
  15. // CHECK:STDOUT: --- fail_out_of_bound.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  19. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  20. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  21. // CHECK:STDOUT: %array_type: type = array_type %int_1, %i32 [template]
  22. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template]
  23. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template]
  24. // CHECK:STDOUT: %tuple.type: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  29. // CHECK:STDOUT: .Int = %Core.Int
  30. // CHECK:STDOUT: import Core//prelude
  31. // CHECK:STDOUT: import Core//prelude/...
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: file {
  36. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  37. // CHECK:STDOUT: .Core = imports.%Core
  38. // CHECK:STDOUT: .a = %a
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core.import = import Core
  41. // CHECK:STDOUT: name_binding_decl {
  42. // CHECK:STDOUT: %a.patt: %array_type = binding_pattern a
  43. // CHECK:STDOUT: %.loc15_1: %array_type = var_pattern %a.patt
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %a.var: ref %array_type = var a
  46. // CHECK:STDOUT: %.loc15_15: type = splice_block %array_type [template = constants.%array_type] {
  47. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  48. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  49. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  50. // CHECK:STDOUT: %array_type: type = array_type %int_1, %i32 [template = constants.%array_type]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %a: ref %array_type = bind_name a, %a.var
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @__global_init() {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  58. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2]
  59. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template = constants.%int_3]
  60. // CHECK:STDOUT: %.loc15: %tuple.type = tuple_literal (%int_1, %int_2, %int_3)
  61. // CHECK:STDOUT: assign file.%a.var, <error>
  62. // CHECK:STDOUT: return
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: