fail_redecl.carbon 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.
  12. // CHECK:STDERR: fn A();
  13. // CHECK:STDERR: ^~~~~~~
  14. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: Previously declared here.
  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.
  21. // CHECK:STDERR: fn B(x: ());
  22. // CHECK:STDERR: ^~~~~~~~~~~~
  23. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: Previously declared here.
  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.
  30. // CHECK:STDERR: fn C(x: ());
  31. // CHECK:STDERR: ^~~~~~~~~~~~
  32. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: Previously declared with parameter count of 0.
  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.
  39. // CHECK:STDERR: fn D();
  40. // CHECK:STDERR: ^~~~~~~
  41. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: Previously declared here.
  42. // CHECK:STDERR: fn D() {}
  43. // CHECK:STDERR: ^~~~~~~~
  44. // CHECK:STDERR:
  45. fn D();
  46. fn E() {}
  47. // CHECK:STDERR: fail_redecl.carbon:[[@LINE+6]]:1: ERROR: Redefinition of `fn E`.
  48. // CHECK:STDERR: fn E() {}
  49. // CHECK:STDERR: ^~~~~~~~
  50. // CHECK:STDERR: fail_redecl.carbon:[[@LINE-4]]:1: Previously defined here.
  51. // CHECK:STDERR: fn E() {}
  52. // CHECK:STDERR: ^~~~~~~~
  53. fn E() {}
  54. // CHECK:STDOUT: --- fail_redecl.carbon
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: constants {
  57. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  58. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  59. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  60. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  61. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  62. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  63. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  64. // CHECK:STDOUT: %.type: type = fn_type @.1 [template]
  65. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  66. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  67. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  68. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  69. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: file {
  73. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  74. // CHECK:STDOUT: .A = %A.decl.loc11
  75. // CHECK:STDOUT: .B = %B.decl.loc21
  76. // CHECK:STDOUT: .C = %C.decl
  77. // CHECK:STDOUT: .D = %D.decl.loc41
  78. // CHECK:STDOUT: .E = %E.decl.loc51
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %A.decl.loc11: %A.type = fn_decl @A [template = constants.%A] {}
  81. // CHECK:STDOUT: %A.decl.loc19: %A.type = fn_decl @A [template = constants.%A] {}
  82. // CHECK:STDOUT: %B.decl.loc21: %B.type = fn_decl @B [template = constants.%B] {
  83. // CHECK:STDOUT: %.loc21_10.1: %.1 = tuple_literal ()
  84. // CHECK:STDOUT: %.loc21_10.2: type = converted %.loc21_10.1, constants.%.1 [template = constants.%.1]
  85. // CHECK:STDOUT: %x.loc21_6.1: %.1 = param x
  86. // CHECK:STDOUT: @B.%x: %.1 = bind_name x, %x.loc21_6.1
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %B.decl.loc29: %B.type = fn_decl @B [template = constants.%B] {
  89. // CHECK:STDOUT: %.loc29_10.1: %.1 = tuple_literal ()
  90. // CHECK:STDOUT: %.loc29_10.2: type = converted %.loc29_10.1, constants.%.1 [template = constants.%.1]
  91. // CHECK:STDOUT: %x.loc29_6.1: %.1 = param x
  92. // CHECK:STDOUT: %x.loc29_6.2: %.1 = bind_name x, %x.loc29_6.1
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {}
  95. // CHECK:STDOUT: %.decl: %.type = fn_decl @.1 [template = constants.%.2] {
  96. // CHECK:STDOUT: %.loc39_10.1: %.1 = tuple_literal ()
  97. // CHECK:STDOUT: %.loc39_10.2: type = converted %.loc39_10.1, constants.%.1 [template = constants.%.1]
  98. // CHECK:STDOUT: %x.loc39_6.1: %.1 = param x
  99. // CHECK:STDOUT: @.1.%x: %.1 = bind_name x, %x.loc39_6.1
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: %D.decl.loc41: %D.type = fn_decl @D [template = constants.%D] {}
  102. // CHECK:STDOUT: %D.decl.loc49: %D.type = fn_decl @D [template = constants.%D] {}
  103. // CHECK:STDOUT: %E.decl.loc51: %E.type = fn_decl @E [template = constants.%E] {}
  104. // CHECK:STDOUT: %E.decl.loc58: %E.type = fn_decl @E [template = constants.%E] {}
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: fn @A();
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: fn @B(%x: %.1);
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: fn @C();
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @.1(%x: %.1);
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @D() {
  116. // CHECK:STDOUT: !entry:
  117. // CHECK:STDOUT: return
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: fn @E() {
  121. // CHECK:STDOUT: !entry:
  122. // CHECK:STDOUT: return
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: !.loc58:
  125. // CHECK:STDOUT: return
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: