fail_redefined.carbon 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/builtin/fail_redefined.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/builtin/fail_redefined.carbon
  10. fn A(n: i32, m: i32) -> i32 = "int.sadd";
  11. // CHECK:STDERR: fail_redefined.carbon:[[@LINE+7]]:1: error: redefinition of `fn A` [RedeclRedef]
  12. // CHECK:STDERR: fn A(n: i32, m: i32) -> i32 { return n; }
  13. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. // CHECK:STDERR: fail_redefined.carbon:[[@LINE-4]]:1: note: previously defined here [RedeclPrevDef]
  15. // CHECK:STDERR: fn A(n: i32, m: i32) -> i32 = "int.sadd";
  16. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  17. // CHECK:STDERR:
  18. fn A(n: i32, m: i32) -> i32 { return n; }
  19. fn B(n: i32, m: i32) -> i32 { return n; }
  20. // CHECK:STDERR: fail_redefined.carbon:[[@LINE+7]]:1: error: redefinition of `fn B` [RedeclRedef]
  21. // CHECK:STDERR: fn B(n: i32, m: i32) -> i32 = "int.sadd";
  22. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. // CHECK:STDERR: fail_redefined.carbon:[[@LINE-4]]:1: note: previously defined here [RedeclPrevDef]
  24. // CHECK:STDERR: fn B(n: i32, m: i32) -> i32 { return n; }
  25. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. // CHECK:STDERR:
  27. fn B(n: i32, m: i32) -> i32 = "int.sadd";
  28. fn C(n: i32, m: i32) -> i32 = "int.sadd";
  29. // CHECK:STDERR: fail_redefined.carbon:[[@LINE+7]]:1: error: redefinition of `fn C` [RedeclRedef]
  30. // CHECK:STDERR: fn C(n: i32, m: i32) -> i32 = "int.sadd";
  31. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. // CHECK:STDERR: fail_redefined.carbon:[[@LINE-4]]:1: note: previously defined here [RedeclPrevDef]
  33. // CHECK:STDERR: fn C(n: i32, m: i32) -> i32 = "int.sadd";
  34. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. // CHECK:STDERR:
  36. fn C(n: i32, m: i32) -> i32 = "int.sadd";
  37. // CHECK:STDOUT: --- fail_redefined.carbon
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: constants {
  40. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  41. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  42. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  43. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  44. // CHECK:STDOUT: %.type.b6a92a.1: type = fn_type @.1 [template]
  45. // CHECK:STDOUT: %.d852be.1: %.type.b6a92a.1 = struct_value () [template]
  46. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  47. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  48. // CHECK:STDOUT: %.type.b6a92a.2: type = fn_type @.2 [template]
  49. // CHECK:STDOUT: %.d852be.2: %.type.b6a92a.2 = struct_value () [template]
  50. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  51. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  52. // CHECK:STDOUT: %.type.b6a92a.3: type = fn_type @.3 [template]
  53. // CHECK:STDOUT: %.d852be.3: %.type.b6a92a.3 = struct_value () [template]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: imports {
  57. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  58. // CHECK:STDOUT: .Int = %Core.Int
  59. // CHECK:STDOUT: import Core//prelude
  60. // CHECK:STDOUT: import Core//prelude/...
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: file {
  65. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  66. // CHECK:STDOUT: .Core = imports.%Core
  67. // CHECK:STDOUT: .A = %A.decl
  68. // CHECK:STDOUT: .B = %B.decl
  69. // CHECK:STDOUT: .C = %C.decl
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Core.import = import Core
  72. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {
  73. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  74. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
  75. // CHECK:STDOUT: %m.patt: %i32 = binding_pattern m
  76. // CHECK:STDOUT: %m.param_patt: %i32 = value_param_pattern %m.patt, runtime_param1
  77. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  78. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param2
  79. // CHECK:STDOUT: } {
  80. // CHECK:STDOUT: %int_32.loc11_25: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  81. // CHECK:STDOUT: %i32.loc11_25: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  82. // CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
  83. // CHECK:STDOUT: %.loc11_9: type = splice_block %i32.loc11_9 [template = constants.%i32] {
  84. // CHECK:STDOUT: %int_32.loc11_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  85. // CHECK:STDOUT: %i32.loc11_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  88. // CHECK:STDOUT: %m.param: %i32 = value_param runtime_param1
  89. // CHECK:STDOUT: %.loc11_17: type = splice_block %i32.loc11_17 [template = constants.%i32] {
  90. // CHECK:STDOUT: %int_32.loc11_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  91. // CHECK:STDOUT: %i32.loc11_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: %m: %i32 = bind_name m, %m.param
  94. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param2
  95. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %.decl.loc19: %.type.b6a92a.1 = fn_decl @.1 [template = constants.%.d852be.1] {
  98. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  99. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
  100. // CHECK:STDOUT: %m.patt: %i32 = binding_pattern m
  101. // CHECK:STDOUT: %m.param_patt: %i32 = value_param_pattern %m.patt, runtime_param1
  102. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  103. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param2
  104. // CHECK:STDOUT: } {
  105. // CHECK:STDOUT: %int_32.loc19_25: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  106. // CHECK:STDOUT: %i32.loc19_25: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  107. // CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
  108. // CHECK:STDOUT: %.loc19_9: type = splice_block %i32.loc19_9 [template = constants.%i32] {
  109. // CHECK:STDOUT: %int_32.loc19_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  110. // CHECK:STDOUT: %i32.loc19_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  113. // CHECK:STDOUT: %m.param: %i32 = value_param runtime_param1
  114. // CHECK:STDOUT: %.loc19_17: type = splice_block %i32.loc19_17 [template = constants.%i32] {
  115. // CHECK:STDOUT: %int_32.loc19_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  116. // CHECK:STDOUT: %i32.loc19_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: %m: %i32 = bind_name m, %m.param
  119. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param2
  120. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  123. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  124. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
  125. // CHECK:STDOUT: %m.patt: %i32 = binding_pattern m
  126. // CHECK:STDOUT: %m.param_patt: %i32 = value_param_pattern %m.patt, runtime_param1
  127. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  128. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param2
  129. // CHECK:STDOUT: } {
  130. // CHECK:STDOUT: %int_32.loc21_25: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  131. // CHECK:STDOUT: %i32.loc21_25: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  132. // CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
  133. // CHECK:STDOUT: %.loc21_9: type = splice_block %i32.loc21_9 [template = constants.%i32] {
  134. // CHECK:STDOUT: %int_32.loc21_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  135. // CHECK:STDOUT: %i32.loc21_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  138. // CHECK:STDOUT: %m.param: %i32 = value_param runtime_param1
  139. // CHECK:STDOUT: %.loc21_17: type = splice_block %i32.loc21_17 [template = constants.%i32] {
  140. // CHECK:STDOUT: %int_32.loc21_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  141. // CHECK:STDOUT: %i32.loc21_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %m: %i32 = bind_name m, %m.param
  144. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param2
  145. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: %.decl.loc29: %.type.b6a92a.2 = fn_decl @.2 [template = constants.%.d852be.2] {
  148. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  149. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
  150. // CHECK:STDOUT: %m.patt: %i32 = binding_pattern m
  151. // CHECK:STDOUT: %m.param_patt: %i32 = value_param_pattern %m.patt, runtime_param1
  152. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  153. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param2
  154. // CHECK:STDOUT: } {
  155. // CHECK:STDOUT: %int_32.loc29_25: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  156. // CHECK:STDOUT: %i32.loc29_25: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  157. // CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
  158. // CHECK:STDOUT: %.loc29_9: type = splice_block %i32.loc29_9 [template = constants.%i32] {
  159. // CHECK:STDOUT: %int_32.loc29_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  160. // CHECK:STDOUT: %i32.loc29_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  163. // CHECK:STDOUT: %m.param: %i32 = value_param runtime_param1
  164. // CHECK:STDOUT: %.loc29_17: type = splice_block %i32.loc29_17 [template = constants.%i32] {
  165. // CHECK:STDOUT: %int_32.loc29_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  166. // CHECK:STDOUT: %i32.loc29_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: %m: %i32 = bind_name m, %m.param
  169. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param2
  170. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {
  173. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  174. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
  175. // CHECK:STDOUT: %m.patt: %i32 = binding_pattern m
  176. // CHECK:STDOUT: %m.param_patt: %i32 = value_param_pattern %m.patt, runtime_param1
  177. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  178. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param2
  179. // CHECK:STDOUT: } {
  180. // CHECK:STDOUT: %int_32.loc31_25: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  181. // CHECK:STDOUT: %i32.loc31_25: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  182. // CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
  183. // CHECK:STDOUT: %.loc31_9: type = splice_block %i32.loc31_9 [template = constants.%i32] {
  184. // CHECK:STDOUT: %int_32.loc31_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  185. // CHECK:STDOUT: %i32.loc31_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  188. // CHECK:STDOUT: %m.param: %i32 = value_param runtime_param1
  189. // CHECK:STDOUT: %.loc31_17: type = splice_block %i32.loc31_17 [template = constants.%i32] {
  190. // CHECK:STDOUT: %int_32.loc31_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  191. // CHECK:STDOUT: %i32.loc31_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT: %m: %i32 = bind_name m, %m.param
  194. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param2
  195. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT: %.decl.loc39: %.type.b6a92a.3 = fn_decl @.3 [template = constants.%.d852be.3] {
  198. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  199. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
  200. // CHECK:STDOUT: %m.patt: %i32 = binding_pattern m
  201. // CHECK:STDOUT: %m.param_patt: %i32 = value_param_pattern %m.patt, runtime_param1
  202. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  203. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param2
  204. // CHECK:STDOUT: } {
  205. // CHECK:STDOUT: %int_32.loc39_25: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  206. // CHECK:STDOUT: %i32.loc39_25: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  207. // CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
  208. // CHECK:STDOUT: %.loc39_9: type = splice_block %i32.loc39_9 [template = constants.%i32] {
  209. // CHECK:STDOUT: %int_32.loc39_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  210. // CHECK:STDOUT: %i32.loc39_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  211. // CHECK:STDOUT: }
  212. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  213. // CHECK:STDOUT: %m.param: %i32 = value_param runtime_param1
  214. // CHECK:STDOUT: %.loc39_17: type = splice_block %i32.loc39_17 [template = constants.%i32] {
  215. // CHECK:STDOUT: %int_32.loc39_17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  216. // CHECK:STDOUT: %i32.loc39_17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT: %m: %i32 = bind_name m, %m.param
  219. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param2
  220. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  221. // CHECK:STDOUT: }
  222. // CHECK:STDOUT: }
  223. // CHECK:STDOUT:
  224. // CHECK:STDOUT: fn @A(%n.param_patt: %i32, %m.param_patt: %i32) -> %i32 = "int.sadd";
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: fn @.1(%n.param_patt: %i32, %m.param_patt: %i32) -> %i32 {
  227. // CHECK:STDOUT: !entry:
  228. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  229. // CHECK:STDOUT: return %n.ref
  230. // CHECK:STDOUT: }
  231. // CHECK:STDOUT:
  232. // CHECK:STDOUT: fn @B(%n.param_patt: %i32, %m.param_patt: %i32) -> %i32 {
  233. // CHECK:STDOUT: !entry:
  234. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  235. // CHECK:STDOUT: return %n.ref
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT:
  238. // CHECK:STDOUT: fn @.2(%n.param_patt: %i32, %m.param_patt: %i32) -> %i32 = "int.sadd";
  239. // CHECK:STDOUT:
  240. // CHECK:STDOUT: fn @C(%n.param_patt: %i32, %m.param_patt: %i32) -> %i32 = "int.sadd";
  241. // CHECK:STDOUT:
  242. // CHECK:STDOUT: fn @.3(%n.param_patt: %i32, %m.param_patt: %i32) -> %i32 = "int.sadd";
  243. // CHECK:STDOUT: