fail_duplicate_decl.carbon 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/let/fail_duplicate_decl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/fail_duplicate_decl.carbon
  10. fn F() {
  11. let a: i32 = 1;
  12. // CHECK:STDERR: fail_duplicate_decl.carbon:[[@LINE+7]]:7: error: duplicate name being declared in the same scope [NameDeclDuplicate]
  13. // CHECK:STDERR: let a: i32 = 2;
  14. // CHECK:STDERR: ^
  15. // CHECK:STDERR: fail_duplicate_decl.carbon:[[@LINE-4]]:7: note: name is previously declared here [NameDeclPrevious]
  16. // CHECK:STDERR: let a: i32 = 1;
  17. // CHECK:STDERR: ^
  18. // CHECK:STDERR:
  19. let a: i32 = 2;
  20. }
  21. // CHECK:STDOUT: --- fail_duplicate_decl.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  25. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  26. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  27. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  28. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
  29. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [template]
  30. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  31. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template]
  32. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  33. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  34. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [template]
  35. // CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [template]
  36. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [template]
  37. // CHECK:STDOUT: %Convert.specific_fn.70c: <specific function> = specific_function %Convert.bound.ab5, @Convert.2(%int_32) [template]
  38. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [template]
  39. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [template]
  40. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [template]
  41. // CHECK:STDOUT: %Convert.specific_fn.787: <specific function> = specific_function %Convert.bound.ef9, @Convert.2(%int_32) [template]
  42. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  47. // CHECK:STDOUT: .Int = %Core.Int
  48. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  49. // CHECK:STDOUT: import Core//prelude
  50. // CHECK:STDOUT: import Core//prelude/...
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: file {
  55. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  56. // CHECK:STDOUT: .Core = imports.%Core
  57. // CHECK:STDOUT: .F = %F.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.import = import Core
  60. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @F() {
  64. // CHECK:STDOUT: !entry:
  65. // CHECK:STDOUT: name_binding_decl {
  66. // CHECK:STDOUT: %a.patt.loc12: %i32 = binding_pattern a
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  69. // CHECK:STDOUT: %.loc12_10: type = splice_block %i32.loc12 [template = constants.%i32] {
  70. // CHECK:STDOUT: %int_32.loc12: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  71. // CHECK:STDOUT: %i32.loc12: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %impl.elem0.loc12: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  74. // CHECK:STDOUT: %bound_method.loc12: <bound method> = bound_method %int_1, %impl.elem0.loc12 [template = constants.%Convert.bound.ab5]
  75. // CHECK:STDOUT: %specific_fn.loc12: <specific function> = specific_function %bound_method.loc12, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
  76. // CHECK:STDOUT: %int.convert_checked.loc12: init %i32 = call %specific_fn.loc12(%int_1) [template = constants.%int_1.5d2]
  77. // CHECK:STDOUT: %.loc12_16.1: %i32 = value_of_initializer %int.convert_checked.loc12 [template = constants.%int_1.5d2]
  78. // CHECK:STDOUT: %.loc12_16.2: %i32 = converted %int_1, %.loc12_16.1 [template = constants.%int_1.5d2]
  79. // CHECK:STDOUT: %a.loc12: %i32 = bind_name a, %.loc12_16.2
  80. // CHECK:STDOUT: name_binding_decl {
  81. // CHECK:STDOUT: %a.patt.loc20: %i32 = binding_pattern a
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  84. // CHECK:STDOUT: %.loc20_10: type = splice_block %i32.loc20 [template = constants.%i32] {
  85. // CHECK:STDOUT: %int_32.loc20: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  86. // CHECK:STDOUT: %i32.loc20: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %impl.elem0.loc20: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  89. // CHECK:STDOUT: %bound_method.loc20: <bound method> = bound_method %int_2, %impl.elem0.loc20 [template = constants.%Convert.bound.ef9]
  90. // CHECK:STDOUT: %specific_fn.loc20: <specific function> = specific_function %bound_method.loc20, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.787]
  91. // CHECK:STDOUT: %int.convert_checked.loc20: init %i32 = call %specific_fn.loc20(%int_2) [template = constants.%int_2.ef8]
  92. // CHECK:STDOUT: %.loc20_16.1: %i32 = value_of_initializer %int.convert_checked.loc20 [template = constants.%int_2.ef8]
  93. // CHECK:STDOUT: %.loc20_16.2: %i32 = converted %int_2, %.loc20_16.1 [template = constants.%int_2.ef8]
  94. // CHECK:STDOUT: %a.loc20: %i32 = bind_name a, %.loc20_16.2
  95. // CHECK:STDOUT: return
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: