fail_redecl.carbon 7.4 KB

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