fail_redecl.carbon 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --no-prelude-import --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/declaration/fail_redecl.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/declaration/fail_redecl.carbon
  13. fn A();
  14. // CHECK:STDERR: fail_redecl.carbon:[[@LINE+7]]:1: error: redeclaration of `fn A` is redundant [RedeclRedundant]
  15. // CHECK:STDERR: fn A();
  16. // CHECK:STDERR: ^~~~~~~
  17. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: note: previously declared here [RedeclPrevDecl]
  18. // CHECK:STDERR: fn A();
  19. // CHECK:STDERR: ^~~~~~~
  20. // CHECK:STDERR:
  21. fn A();
  22. fn B(x: ());
  23. // CHECK:STDERR: fail_redecl.carbon:[[@LINE+7]]:1: error: redeclaration of `fn B` is redundant [RedeclRedundant]
  24. // CHECK:STDERR: fn B(x: ());
  25. // CHECK:STDERR: ^~~~~~~~~~~~
  26. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: note: previously declared here [RedeclPrevDecl]
  27. // CHECK:STDERR: fn B(x: ());
  28. // CHECK:STDERR: ^~~~~~~~~~~~
  29. // CHECK:STDERR:
  30. fn B(x: ());
  31. fn C();
  32. // CHECK:STDERR: fail_redecl.carbon:[[@LINE+7]]:1: error: redeclaration differs because of parameter count of 1 [RedeclParamCountDiffers]
  33. // CHECK:STDERR: fn C(x: ());
  34. // CHECK:STDERR: ^~~~~~~~~~~~
  35. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: note: previously declared with parameter count of 0 [RedeclParamCountPrevious]
  36. // CHECK:STDERR: fn C();
  37. // CHECK:STDERR: ^~~~~~~
  38. // CHECK:STDERR:
  39. fn C(x: ());
  40. fn D() {}
  41. // CHECK:STDERR: fail_redecl.carbon:[[@LINE+7]]:1: error: redeclaration of `fn D` is redundant [RedeclRedundant]
  42. // CHECK:STDERR: fn D();
  43. // CHECK:STDERR: ^~~~~~~
  44. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: note: previously declared here [RedeclPrevDecl]
  45. // CHECK:STDERR: fn D() {}
  46. // CHECK:STDERR: ^~~~~~~~
  47. // CHECK:STDERR:
  48. fn D();
  49. fn E() {}
  50. // CHECK:STDERR: fail_redecl.carbon:[[@LINE+7]]:1: error: redefinition of `fn E` [RedeclRedef]
  51. // CHECK:STDERR: fn E() {}
  52. // CHECK:STDERR: ^~~~~~~~
  53. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: note: previously defined here [RedeclPrevDef]
  54. // CHECK:STDERR: fn E() {}
  55. // CHECK:STDERR: ^~~~~~~~
  56. // CHECK:STDERR:
  57. fn E() {}
  58. // CHECK:STDOUT: --- fail_redecl.carbon
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: constants {
  61. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  62. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  63. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  64. // CHECK:STDOUT: %pattern_type: type = pattern_type %empty_tuple.type [concrete]
  65. // CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
  66. // CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
  67. // CHECK:STDOUT: %C.type.de0bfe.1: type = fn_type @C.1 [concrete]
  68. // CHECK:STDOUT: %C.1b0370.1: %C.type.de0bfe.1 = struct_value () [concrete]
  69. // CHECK:STDOUT: %C.type.de0bfe.2: type = fn_type @C.2 [concrete]
  70. // CHECK:STDOUT: %C.1b0370.2: %C.type.de0bfe.2 = struct_value () [concrete]
  71. // CHECK:STDOUT: %D.type: type = fn_type @D [concrete]
  72. // CHECK:STDOUT: %D: %D.type = struct_value () [concrete]
  73. // CHECK:STDOUT: %E.type.851869.1: type = fn_type @E.1 [concrete]
  74. // CHECK:STDOUT: %E.237d29.1: %E.type.851869.1 = struct_value () [concrete]
  75. // CHECK:STDOUT: %E.type.851869.2: type = fn_type @E.2 [concrete]
  76. // CHECK:STDOUT: %E.237d29.2: %E.type.851869.2 = struct_value () [concrete]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: file {
  80. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  81. // CHECK:STDOUT: .A = %A.decl.loc14
  82. // CHECK:STDOUT: .B = %B.decl.loc24
  83. // CHECK:STDOUT: .C = %C.decl.loc34
  84. // CHECK:STDOUT: .D = %D.decl.loc44
  85. // CHECK:STDOUT: .E = %E.decl.loc54
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %A.decl.loc14: %A.type = fn_decl @A [concrete = constants.%A] {} {}
  88. // CHECK:STDOUT: %A.decl.loc22: %A.type = fn_decl @A [concrete = constants.%A] {} {}
  89. // CHECK:STDOUT: %B.decl.loc24: %B.type = fn_decl @B [concrete = constants.%B] {
  90. // CHECK:STDOUT: %x.patt: %pattern_type = binding_pattern x [concrete]
  91. // CHECK:STDOUT: %x.param_patt: %pattern_type = value_param_pattern %x.patt, call_param0 [concrete]
  92. // CHECK:STDOUT: } {
  93. // CHECK:STDOUT: %x.param.loc24: %empty_tuple.type = value_param call_param0
  94. // CHECK:STDOUT: %.loc24_10.1: type = splice_block %.loc24_10.3 [concrete = constants.%empty_tuple.type] {
  95. // CHECK:STDOUT: %.loc24_10.2: %empty_tuple.type = tuple_literal ()
  96. // CHECK:STDOUT: %.loc24_10.3: type = converted %.loc24_10.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %x.loc24: %empty_tuple.type = bind_name x, %x.param.loc24
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: %B.decl.loc32: %B.type = fn_decl @B [concrete = constants.%B] {
  101. // CHECK:STDOUT: %x.patt: %pattern_type = binding_pattern x [concrete]
  102. // CHECK:STDOUT: %x.param_patt: %pattern_type = value_param_pattern %x.patt, call_param0 [concrete]
  103. // CHECK:STDOUT: } {
  104. // CHECK:STDOUT: %x.param.loc32: %empty_tuple.type = value_param call_param0
  105. // CHECK:STDOUT: %.loc32_10.1: type = splice_block %.loc32_10.3 [concrete = constants.%empty_tuple.type] {
  106. // CHECK:STDOUT: %.loc32_10.2: %empty_tuple.type = tuple_literal ()
  107. // CHECK:STDOUT: %.loc32_10.3: type = converted %.loc32_10.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %x.loc32: %empty_tuple.type = bind_name x, %x.param.loc32
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %C.decl.loc34: %C.type.de0bfe.1 = fn_decl @C.1 [concrete = constants.%C.1b0370.1] {} {}
  112. // CHECK:STDOUT: %C.decl.loc42: %C.type.de0bfe.2 = fn_decl @C.2 [concrete = constants.%C.1b0370.2] {
  113. // CHECK:STDOUT: %x.patt: %pattern_type = binding_pattern x [concrete]
  114. // CHECK:STDOUT: %x.param_patt: %pattern_type = value_param_pattern %x.patt, call_param0 [concrete]
  115. // CHECK:STDOUT: } {
  116. // CHECK:STDOUT: %x.param: %empty_tuple.type = value_param call_param0
  117. // CHECK:STDOUT: %.loc42_10.1: type = splice_block %.loc42_10.3 [concrete = constants.%empty_tuple.type] {
  118. // CHECK:STDOUT: %.loc42_10.2: %empty_tuple.type = tuple_literal ()
  119. // CHECK:STDOUT: %.loc42_10.3: type = converted %.loc42_10.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: %x: %empty_tuple.type = bind_name x, %x.param
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: %D.decl.loc44: %D.type = fn_decl @D [concrete = constants.%D] {} {}
  124. // CHECK:STDOUT: %D.decl.loc52: %D.type = fn_decl @D [concrete = constants.%D] {} {}
  125. // CHECK:STDOUT: %E.decl.loc54: %E.type.851869.1 = fn_decl @E.1 [concrete = constants.%E.237d29.1] {} {}
  126. // CHECK:STDOUT: %E.decl.loc62: %E.type.851869.2 = fn_decl @E.2 [concrete = constants.%E.237d29.2] {} {}
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: fn @A();
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn @B(%x.param.loc24: %empty_tuple.type);
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: fn @C.1();
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: fn @C.2(%x.param: %empty_tuple.type);
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: fn @D() {
  138. // CHECK:STDOUT: !entry:
  139. // CHECK:STDOUT: return
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: fn @E.1() {
  143. // CHECK:STDOUT: !entry:
  144. // CHECK:STDOUT: return
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: fn @E.2() {
  148. // CHECK:STDOUT: !entry:
  149. // CHECK:STDOUT: return
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT: