fail_out_of_bound.carbon 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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]]:24: error: cannot initialize array of 1 element from 3 initializers [ArrayInitFromLiteralArgCountMismatch]
  11. // CHECK:STDERR: var a: array(i32, 1) = (1, 2, 3);
  12. // CHECK:STDERR: ^~~~~~~~~
  13. // CHECK:STDERR:
  14. var a: array(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 [concrete]
  19. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  20. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  21. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  22. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  23. // CHECK:STDOUT: %array_type: type = array_type %int_1, %i32 [concrete]
  24. // CHECK:STDOUT: %pattern_type.a98: type = pattern_type %array_type [concrete]
  25. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete]
  26. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete]
  27. // CHECK:STDOUT: %tuple.type: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [concrete]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: imports {
  31. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  32. // CHECK:STDOUT: .Int = %Core.Int
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/...
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: file {
  40. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  41. // CHECK:STDOUT: .Core = imports.%Core
  42. // CHECK:STDOUT: .a = %a
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %Core.import = import Core
  45. // CHECK:STDOUT: name_binding_decl {
  46. // CHECK:STDOUT: %a.patt: %pattern_type.a98 = binding_pattern a [concrete]
  47. // CHECK:STDOUT: %.loc15_1: %pattern_type.a98 = var_pattern %a.patt [concrete]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %a.var: ref %array_type = var a
  50. // CHECK:STDOUT: %.loc15_20: type = splice_block %array_type [concrete = constants.%array_type] {
  51. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  52. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  53. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  54. // CHECK:STDOUT: %array_type: type = array_type %int_1, %i32 [concrete = constants.%array_type]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %a: ref %array_type = bind_name a, %a.var
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @__global_init() {
  60. // CHECK:STDOUT: !entry:
  61. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  62. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2]
  63. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3]
  64. // CHECK:STDOUT: %.loc15: %tuple.type = tuple_literal (%int_1, %int_2, %int_3)
  65. // CHECK:STDOUT: assign file.%a.var, <error>
  66. // CHECK:STDOUT: return
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: