fail_redecl.carbon 7.2 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 [template]
  59. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  60. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  61. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  62. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  63. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  64. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  65. // CHECK:STDOUT: %.type.b6a92a.1: type = fn_type @.1 [template]
  66. // CHECK:STDOUT: %.d852be.1: %.type.b6a92a.1 = struct_value () [template]
  67. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  68. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  69. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  70. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  71. // CHECK:STDOUT: %.type.b6a92a.2: type = fn_type @.2 [template]
  72. // CHECK:STDOUT: %.d852be.2: %.type.b6a92a.2 = struct_value () [template]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: file {
  76. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  77. // CHECK:STDOUT: .A = %A.decl.loc11
  78. // CHECK:STDOUT: .B = %B.decl.loc21
  79. // CHECK:STDOUT: .C = %C.decl
  80. // CHECK:STDOUT: .D = %D.decl.loc41
  81. // CHECK:STDOUT: .E = %E.decl
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %A.decl.loc11: %A.type = fn_decl @A [template = constants.%A] {} {}
  84. // CHECK:STDOUT: %A.decl.loc19: %A.type = fn_decl @A [template = constants.%A] {} {}
  85. // CHECK:STDOUT: %B.decl.loc21: %B.type = fn_decl @B [template = 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, runtime_param0
  88. // CHECK:STDOUT: } {
  89. // CHECK:STDOUT: %x.param.loc21: %empty_tuple.type = value_param runtime_param0
  90. // CHECK:STDOUT: %.loc21_10.1: type = splice_block %.loc21_10.3 [template = 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 [template = 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 [template = 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, runtime_param0
  99. // CHECK:STDOUT: } {
  100. // CHECK:STDOUT: %x.param.loc29: %empty_tuple.type = value_param runtime_param0
  101. // CHECK:STDOUT: %.loc29_10.1: type = splice_block %.loc29_10.3 [template = 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 [template = 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: %C.type = fn_decl @C [template = constants.%C] {} {}
  108. // CHECK:STDOUT: %.decl.loc39: %.type.b6a92a.1 = fn_decl @.1 [template = constants.%.d852be.1] {
  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, runtime_param0
  111. // CHECK:STDOUT: } {
  112. // CHECK:STDOUT: %x.param: %empty_tuple.type = value_param runtime_param0
  113. // CHECK:STDOUT: %.loc39_10.1: type = splice_block %.loc39_10.3 [template = 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 [template = 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 [template = constants.%D] {} {}
  120. // CHECK:STDOUT: %D.decl.loc49: %D.type = fn_decl @D [template = constants.%D] {} {}
  121. // CHECK:STDOUT: %E.decl: %E.type = fn_decl @E [template = constants.%E] {} {}
  122. // CHECK:STDOUT: %.decl.loc59: %.type.b6a92a.2 = fn_decl @.2 [template = constants.%.d852be.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();
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn @.1(%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() {
  139. // CHECK:STDOUT: !entry:
  140. // CHECK:STDOUT: return
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: fn @.2() {
  144. // CHECK:STDOUT: !entry:
  145. // CHECK:STDOUT: return
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: