fail_redecl.carbon 7.9 KB

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