fail_redefined.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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`.
  12. // CHECK:STDERR: fn A(n: i32, m: i32) -> i32 { return n; }
  13. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. // CHECK:STDERR: fail_redefined.carbon:[[@LINE-4]]:1: Previously defined here.
  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`.
  21. // CHECK:STDERR: fn B(n: i32, m: i32) -> i32 = "int.sadd";
  22. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. // CHECK:STDERR: fail_redefined.carbon:[[@LINE-4]]:1: Previously defined here.
  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+6]]:1: ERROR: Redefinition of `fn C`.
  30. // CHECK:STDERR: fn C(n: i32, m: i32) -> i32 = "int.sadd";
  31. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. // CHECK:STDERR: fail_redefined.carbon:[[@LINE-4]]:1: Previously defined here.
  33. // CHECK:STDERR: fn C(n: i32, m: i32) -> i32 = "int.sadd";
  34. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. fn C(n: i32, m: i32) -> i32 = "int.sadd";
  36. // CHECK:STDOUT: --- fail_redefined.carbon
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: constants {
  39. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  40. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  41. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  42. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  43. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  44. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  45. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  46. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  47. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: file {
  51. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  52. // CHECK:STDOUT: .Core = %Core
  53. // CHECK:STDOUT: .A = %A.decl.loc11
  54. // CHECK:STDOUT: .B = %B.decl.loc21
  55. // CHECK:STDOUT: .C = %C.decl.loc31
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  58. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  59. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  60. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  61. // CHECK:STDOUT: %A.decl.loc11: %A.type = fn_decl @A [template = constants.%A] {
  62. // CHECK:STDOUT: %int.make_type_32.loc11_9: init type = call constants.%Int32() [template = i32]
  63. // CHECK:STDOUT: %.loc11_9.1: type = value_of_initializer %int.make_type_32.loc11_9 [template = i32]
  64. // CHECK:STDOUT: %.loc11_9.2: type = converted %int.make_type_32.loc11_9, %.loc11_9.1 [template = i32]
  65. // CHECK:STDOUT: %n.loc11_6.1: i32 = param n
  66. // CHECK:STDOUT: %n.loc11_6.2: i32 = bind_name n, %n.loc11_6.1
  67. // CHECK:STDOUT: %int.make_type_32.loc11_17: init type = call constants.%Int32() [template = i32]
  68. // CHECK:STDOUT: %.loc11_17.1: type = value_of_initializer %int.make_type_32.loc11_17 [template = i32]
  69. // CHECK:STDOUT: %.loc11_17.2: type = converted %int.make_type_32.loc11_17, %.loc11_17.1 [template = i32]
  70. // CHECK:STDOUT: %m.loc11_14.1: i32 = param m
  71. // CHECK:STDOUT: %m.loc11_14.2: i32 = bind_name m, %m.loc11_14.1
  72. // CHECK:STDOUT: %int.make_type_32.loc11_25: init type = call constants.%Int32() [template = i32]
  73. // CHECK:STDOUT: %.loc11_25.1: type = value_of_initializer %int.make_type_32.loc11_25 [template = i32]
  74. // CHECK:STDOUT: %.loc11_25.2: type = converted %int.make_type_32.loc11_25, %.loc11_25.1 [template = i32]
  75. // CHECK:STDOUT: %return.var.loc11: ref i32 = var <return slot>
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  78. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  79. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  80. // CHECK:STDOUT: %A.decl.loc19: %A.type = fn_decl @A [template = constants.%A] {
  81. // CHECK:STDOUT: %int.make_type_32.loc19_9: init type = call constants.%Int32() [template = i32]
  82. // CHECK:STDOUT: %.loc19_9.1: type = value_of_initializer %int.make_type_32.loc19_9 [template = i32]
  83. // CHECK:STDOUT: %.loc19_9.2: type = converted %int.make_type_32.loc19_9, %.loc19_9.1 [template = i32]
  84. // CHECK:STDOUT: %n.loc19_6.1: i32 = param n
  85. // CHECK:STDOUT: @A.%n: i32 = bind_name n, %n.loc19_6.1
  86. // CHECK:STDOUT: %int.make_type_32.loc19_17: init type = call constants.%Int32() [template = i32]
  87. // CHECK:STDOUT: %.loc19_17.1: type = value_of_initializer %int.make_type_32.loc19_17 [template = i32]
  88. // CHECK:STDOUT: %.loc19_17.2: type = converted %int.make_type_32.loc19_17, %.loc19_17.1 [template = i32]
  89. // CHECK:STDOUT: %m.loc19_14.1: i32 = param m
  90. // CHECK:STDOUT: @A.%m: i32 = bind_name m, %m.loc19_14.1
  91. // CHECK:STDOUT: %int.make_type_32.loc19_25: init type = call constants.%Int32() [template = i32]
  92. // CHECK:STDOUT: %.loc19_25.1: type = value_of_initializer %int.make_type_32.loc19_25 [template = i32]
  93. // CHECK:STDOUT: %.loc19_25.2: type = converted %int.make_type_32.loc19_25, %.loc19_25.1 [template = i32]
  94. // CHECK:STDOUT: @A.%return: ref i32 = var <return slot>
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  97. // CHECK:STDOUT: %import_ref.8: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  98. // CHECK:STDOUT: %import_ref.9: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  99. // CHECK:STDOUT: %B.decl.loc21: %B.type = fn_decl @B [template = constants.%B] {
  100. // CHECK:STDOUT: %int.make_type_32.loc21_9: init type = call constants.%Int32() [template = i32]
  101. // CHECK:STDOUT: %.loc21_9.1: type = value_of_initializer %int.make_type_32.loc21_9 [template = i32]
  102. // CHECK:STDOUT: %.loc21_9.2: type = converted %int.make_type_32.loc21_9, %.loc21_9.1 [template = i32]
  103. // CHECK:STDOUT: %n.loc21_6.1: i32 = param n
  104. // CHECK:STDOUT: %n.loc21_6.2: i32 = bind_name n, %n.loc21_6.1
  105. // CHECK:STDOUT: %int.make_type_32.loc21_17: init type = call constants.%Int32() [template = i32]
  106. // CHECK:STDOUT: %.loc21_17.1: type = value_of_initializer %int.make_type_32.loc21_17 [template = i32]
  107. // CHECK:STDOUT: %.loc21_17.2: type = converted %int.make_type_32.loc21_17, %.loc21_17.1 [template = i32]
  108. // CHECK:STDOUT: %m.loc21_14.1: i32 = param m
  109. // CHECK:STDOUT: %m.loc21_14.2: i32 = bind_name m, %m.loc21_14.1
  110. // CHECK:STDOUT: %int.make_type_32.loc21_25: init type = call constants.%Int32() [template = i32]
  111. // CHECK:STDOUT: %.loc21_25.1: type = value_of_initializer %int.make_type_32.loc21_25 [template = i32]
  112. // CHECK:STDOUT: %.loc21_25.2: type = converted %int.make_type_32.loc21_25, %.loc21_25.1 [template = i32]
  113. // CHECK:STDOUT: %return.var.loc21: ref i32 = var <return slot>
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: %import_ref.10: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  116. // CHECK:STDOUT: %import_ref.11: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  117. // CHECK:STDOUT: %import_ref.12: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  118. // CHECK:STDOUT: %B.decl.loc29: %B.type = fn_decl @B [template = constants.%B] {
  119. // CHECK:STDOUT: %int.make_type_32.loc29_9: init type = call constants.%Int32() [template = i32]
  120. // CHECK:STDOUT: %.loc29_9.1: type = value_of_initializer %int.make_type_32.loc29_9 [template = i32]
  121. // CHECK:STDOUT: %.loc29_9.2: type = converted %int.make_type_32.loc29_9, %.loc29_9.1 [template = i32]
  122. // CHECK:STDOUT: %n.loc29_6.1: i32 = param n
  123. // CHECK:STDOUT: @B.%n: i32 = bind_name n, %n.loc29_6.1
  124. // CHECK:STDOUT: %int.make_type_32.loc29_17: init type = call constants.%Int32() [template = i32]
  125. // CHECK:STDOUT: %.loc29_17.1: type = value_of_initializer %int.make_type_32.loc29_17 [template = i32]
  126. // CHECK:STDOUT: %.loc29_17.2: type = converted %int.make_type_32.loc29_17, %.loc29_17.1 [template = i32]
  127. // CHECK:STDOUT: %m.loc29_14.1: i32 = param m
  128. // CHECK:STDOUT: @B.%m: i32 = bind_name m, %m.loc29_14.1
  129. // CHECK:STDOUT: %int.make_type_32.loc29_25: init type = call constants.%Int32() [template = i32]
  130. // CHECK:STDOUT: %.loc29_25.1: type = value_of_initializer %int.make_type_32.loc29_25 [template = i32]
  131. // CHECK:STDOUT: %.loc29_25.2: type = converted %int.make_type_32.loc29_25, %.loc29_25.1 [template = i32]
  132. // CHECK:STDOUT: @B.%return: ref i32 = var <return slot>
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT: %import_ref.13: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  135. // CHECK:STDOUT: %import_ref.14: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  136. // CHECK:STDOUT: %import_ref.15: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  137. // CHECK:STDOUT: %C.decl.loc31: %C.type = fn_decl @C [template = constants.%C] {
  138. // CHECK:STDOUT: %int.make_type_32.loc31_9: init type = call constants.%Int32() [template = i32]
  139. // CHECK:STDOUT: %.loc31_9.1: type = value_of_initializer %int.make_type_32.loc31_9 [template = i32]
  140. // CHECK:STDOUT: %.loc31_9.2: type = converted %int.make_type_32.loc31_9, %.loc31_9.1 [template = i32]
  141. // CHECK:STDOUT: %n.loc31_6.1: i32 = param n
  142. // CHECK:STDOUT: %n.loc31_6.2: i32 = bind_name n, %n.loc31_6.1
  143. // CHECK:STDOUT: %int.make_type_32.loc31_17: init type = call constants.%Int32() [template = i32]
  144. // CHECK:STDOUT: %.loc31_17.1: type = value_of_initializer %int.make_type_32.loc31_17 [template = i32]
  145. // CHECK:STDOUT: %.loc31_17.2: type = converted %int.make_type_32.loc31_17, %.loc31_17.1 [template = i32]
  146. // CHECK:STDOUT: %m.loc31_14.1: i32 = param m
  147. // CHECK:STDOUT: %m.loc31_14.2: i32 = bind_name m, %m.loc31_14.1
  148. // CHECK:STDOUT: %int.make_type_32.loc31_25: init type = call constants.%Int32() [template = i32]
  149. // CHECK:STDOUT: %.loc31_25.1: type = value_of_initializer %int.make_type_32.loc31_25 [template = i32]
  150. // CHECK:STDOUT: %.loc31_25.2: type = converted %int.make_type_32.loc31_25, %.loc31_25.1 [template = i32]
  151. // CHECK:STDOUT: %return.var.loc31: ref i32 = var <return slot>
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT: %import_ref.16: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  154. // CHECK:STDOUT: %import_ref.17: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  155. // CHECK:STDOUT: %import_ref.18: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  156. // CHECK:STDOUT: %C.decl.loc38: %C.type = fn_decl @C [template = constants.%C] {
  157. // CHECK:STDOUT: %int.make_type_32.loc38_9: init type = call constants.%Int32() [template = i32]
  158. // CHECK:STDOUT: %.loc38_9.1: type = value_of_initializer %int.make_type_32.loc38_9 [template = i32]
  159. // CHECK:STDOUT: %.loc38_9.2: type = converted %int.make_type_32.loc38_9, %.loc38_9.1 [template = i32]
  160. // CHECK:STDOUT: %n.loc38_6.1: i32 = param n
  161. // CHECK:STDOUT: @C.%n: i32 = bind_name n, %n.loc38_6.1
  162. // CHECK:STDOUT: %int.make_type_32.loc38_17: init type = call constants.%Int32() [template = i32]
  163. // CHECK:STDOUT: %.loc38_17.1: type = value_of_initializer %int.make_type_32.loc38_17 [template = i32]
  164. // CHECK:STDOUT: %.loc38_17.2: type = converted %int.make_type_32.loc38_17, %.loc38_17.1 [template = i32]
  165. // CHECK:STDOUT: %m.loc38_14.1: i32 = param m
  166. // CHECK:STDOUT: @C.%m: i32 = bind_name m, %m.loc38_14.1
  167. // CHECK:STDOUT: %int.make_type_32.loc38_25: init type = call constants.%Int32() [template = i32]
  168. // CHECK:STDOUT: %.loc38_25.1: type = value_of_initializer %int.make_type_32.loc38_25 [template = i32]
  169. // CHECK:STDOUT: %.loc38_25.2: type = converted %int.make_type_32.loc38_25, %.loc38_25.1 [template = i32]
  170. // CHECK:STDOUT: @C.%return: ref i32 = var <return slot>
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: fn @A(%n: i32, %m: i32) -> i32 = "int.sadd" {
  177. // CHECK:STDOUT: !entry:
  178. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  179. // CHECK:STDOUT: return %n.ref
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: fn @B(%n: i32, %m: i32) -> i32 = "int.sadd" {
  183. // CHECK:STDOUT: !entry:
  184. // CHECK:STDOUT: %n.ref: i32 = name_ref n, file.%n.loc21_6.2
  185. // CHECK:STDOUT: return %n.ref
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: fn @C(%n: i32, %m: i32) -> i32 = "int.sadd";
  189. // CHECK:STDOUT: