fail_redefined.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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: note: 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: note: 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: note: 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: imports {
  51. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  52. // CHECK:STDOUT: .Int32 = %import_ref
  53. // CHECK:STDOUT: import Core//prelude
  54. // CHECK:STDOUT: import Core//prelude/operators
  55. // CHECK:STDOUT: import Core//prelude/types
  56. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  57. // CHECK:STDOUT: import Core//prelude/operators/as
  58. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  59. // CHECK:STDOUT: import Core//prelude/operators/comparison
  60. // CHECK:STDOUT: import Core//prelude/types/bool
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  67. // CHECK:STDOUT: .Core = imports.%Core
  68. // CHECK:STDOUT: .A = %A.decl.loc11
  69. // CHECK:STDOUT: .B = %B.decl.loc21
  70. // CHECK:STDOUT: .C = %C.decl.loc31
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Core.import = import Core
  73. // CHECK:STDOUT: %A.decl.loc11: %A.type = fn_decl @A [template = constants.%A] {
  74. // CHECK:STDOUT: %n.patt: i32 = binding_pattern n
  75. // CHECK:STDOUT: %m.patt: i32 = binding_pattern m
  76. // CHECK:STDOUT: } {
  77. // CHECK:STDOUT: %int.make_type_32.loc11_9: init type = call constants.%Int32() [template = i32]
  78. // CHECK:STDOUT: %.loc11_9.1: type = value_of_initializer %int.make_type_32.loc11_9 [template = i32]
  79. // CHECK:STDOUT: %.loc11_9.2: type = converted %int.make_type_32.loc11_9, %.loc11_9.1 [template = i32]
  80. // CHECK:STDOUT: %n.param.loc11: i32 = param n, runtime_param0
  81. // CHECK:STDOUT: %n.loc11: i32 = bind_name n, %n.param.loc11
  82. // CHECK:STDOUT: %int.make_type_32.loc11_17: init type = call constants.%Int32() [template = i32]
  83. // CHECK:STDOUT: %.loc11_17.1: type = value_of_initializer %int.make_type_32.loc11_17 [template = i32]
  84. // CHECK:STDOUT: %.loc11_17.2: type = converted %int.make_type_32.loc11_17, %.loc11_17.1 [template = i32]
  85. // CHECK:STDOUT: %m.param.loc11: i32 = param m, runtime_param1
  86. // CHECK:STDOUT: %m.loc11: i32 = bind_name m, %m.param.loc11
  87. // CHECK:STDOUT: %int.make_type_32.loc11_25: init type = call constants.%Int32() [template = i32]
  88. // CHECK:STDOUT: %.loc11_25.1: type = value_of_initializer %int.make_type_32.loc11_25 [template = i32]
  89. // CHECK:STDOUT: %.loc11_25.2: type = converted %int.make_type_32.loc11_25, %.loc11_25.1 [template = i32]
  90. // CHECK:STDOUT: %return.var.loc11: ref i32 = var <return slot>
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: %A.decl.loc19: %A.type = fn_decl @A [template = constants.%A] {
  93. // CHECK:STDOUT: %n.patt: i32 = binding_pattern n
  94. // CHECK:STDOUT: %m.patt: i32 = binding_pattern m
  95. // CHECK:STDOUT: } {
  96. // CHECK:STDOUT: %int.make_type_32.loc19_9: init type = call constants.%Int32() [template = i32]
  97. // CHECK:STDOUT: %.loc19_9.1: type = value_of_initializer %int.make_type_32.loc19_9 [template = i32]
  98. // CHECK:STDOUT: %.loc19_9.2: type = converted %int.make_type_32.loc19_9, %.loc19_9.1 [template = i32]
  99. // CHECK:STDOUT: %n.param.loc19: i32 = param n, runtime_param0
  100. // CHECK:STDOUT: %n.loc19: i32 = bind_name n, %n.param.loc19
  101. // CHECK:STDOUT: %int.make_type_32.loc19_17: init type = call constants.%Int32() [template = i32]
  102. // CHECK:STDOUT: %.loc19_17.1: type = value_of_initializer %int.make_type_32.loc19_17 [template = i32]
  103. // CHECK:STDOUT: %.loc19_17.2: type = converted %int.make_type_32.loc19_17, %.loc19_17.1 [template = i32]
  104. // CHECK:STDOUT: %m.param.loc19: i32 = param m, runtime_param1
  105. // CHECK:STDOUT: %m.loc19: i32 = bind_name m, %m.param.loc19
  106. // CHECK:STDOUT: %int.make_type_32.loc19_25: init type = call constants.%Int32() [template = i32]
  107. // CHECK:STDOUT: %.loc19_25.1: type = value_of_initializer %int.make_type_32.loc19_25 [template = i32]
  108. // CHECK:STDOUT: %.loc19_25.2: type = converted %int.make_type_32.loc19_25, %.loc19_25.1 [template = i32]
  109. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %B.decl.loc21: %B.type = fn_decl @B [template = constants.%B] {
  112. // CHECK:STDOUT: %n.patt: i32 = binding_pattern n
  113. // CHECK:STDOUT: %m.patt: i32 = binding_pattern m
  114. // CHECK:STDOUT: } {
  115. // CHECK:STDOUT: %int.make_type_32.loc21_9: init type = call constants.%Int32() [template = i32]
  116. // CHECK:STDOUT: %.loc21_9.1: type = value_of_initializer %int.make_type_32.loc21_9 [template = i32]
  117. // CHECK:STDOUT: %.loc21_9.2: type = converted %int.make_type_32.loc21_9, %.loc21_9.1 [template = i32]
  118. // CHECK:STDOUT: %n.param.loc21: i32 = param n, runtime_param0
  119. // CHECK:STDOUT: %n.loc21: i32 = bind_name n, %n.param.loc21
  120. // CHECK:STDOUT: %int.make_type_32.loc21_17: init type = call constants.%Int32() [template = i32]
  121. // CHECK:STDOUT: %.loc21_17.1: type = value_of_initializer %int.make_type_32.loc21_17 [template = i32]
  122. // CHECK:STDOUT: %.loc21_17.2: type = converted %int.make_type_32.loc21_17, %.loc21_17.1 [template = i32]
  123. // CHECK:STDOUT: %m.param.loc21: i32 = param m, runtime_param1
  124. // CHECK:STDOUT: %m.loc21: i32 = bind_name m, %m.param.loc21
  125. // CHECK:STDOUT: %int.make_type_32.loc21_25: init type = call constants.%Int32() [template = i32]
  126. // CHECK:STDOUT: %.loc21_25.1: type = value_of_initializer %int.make_type_32.loc21_25 [template = i32]
  127. // CHECK:STDOUT: %.loc21_25.2: type = converted %int.make_type_32.loc21_25, %.loc21_25.1 [template = i32]
  128. // CHECK:STDOUT: %return.var.loc21: ref i32 = var <return slot>
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %B.decl.loc29: %B.type = fn_decl @B [template = constants.%B] {
  131. // CHECK:STDOUT: %n.patt: i32 = binding_pattern n
  132. // CHECK:STDOUT: %m.patt: i32 = binding_pattern m
  133. // CHECK:STDOUT: } {
  134. // CHECK:STDOUT: %int.make_type_32.loc29_9: init type = call constants.%Int32() [template = i32]
  135. // CHECK:STDOUT: %.loc29_9.1: type = value_of_initializer %int.make_type_32.loc29_9 [template = i32]
  136. // CHECK:STDOUT: %.loc29_9.2: type = converted %int.make_type_32.loc29_9, %.loc29_9.1 [template = i32]
  137. // CHECK:STDOUT: %n.param.loc29: i32 = param n, runtime_param0
  138. // CHECK:STDOUT: %n.loc29: i32 = bind_name n, %n.param.loc29
  139. // CHECK:STDOUT: %int.make_type_32.loc29_17: init type = call constants.%Int32() [template = i32]
  140. // CHECK:STDOUT: %.loc29_17.1: type = value_of_initializer %int.make_type_32.loc29_17 [template = i32]
  141. // CHECK:STDOUT: %.loc29_17.2: type = converted %int.make_type_32.loc29_17, %.loc29_17.1 [template = i32]
  142. // CHECK:STDOUT: %m.param.loc29: i32 = param m, runtime_param1
  143. // CHECK:STDOUT: %m.loc29: i32 = bind_name m, %m.param.loc29
  144. // CHECK:STDOUT: %int.make_type_32.loc29_25: init type = call constants.%Int32() [template = i32]
  145. // CHECK:STDOUT: %.loc29_25.1: type = value_of_initializer %int.make_type_32.loc29_25 [template = i32]
  146. // CHECK:STDOUT: %.loc29_25.2: type = converted %int.make_type_32.loc29_25, %.loc29_25.1 [template = i32]
  147. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: %C.decl.loc31: %C.type = fn_decl @C [template = constants.%C] {
  150. // CHECK:STDOUT: %n.patt: i32 = binding_pattern n
  151. // CHECK:STDOUT: %m.patt: i32 = binding_pattern m
  152. // CHECK:STDOUT: } {
  153. // CHECK:STDOUT: %int.make_type_32.loc31_9: init type = call constants.%Int32() [template = i32]
  154. // CHECK:STDOUT: %.loc31_9.1: type = value_of_initializer %int.make_type_32.loc31_9 [template = i32]
  155. // CHECK:STDOUT: %.loc31_9.2: type = converted %int.make_type_32.loc31_9, %.loc31_9.1 [template = i32]
  156. // CHECK:STDOUT: %n.param.loc31: i32 = param n, runtime_param0
  157. // CHECK:STDOUT: %n.loc31: i32 = bind_name n, %n.param.loc31
  158. // CHECK:STDOUT: %int.make_type_32.loc31_17: init type = call constants.%Int32() [template = i32]
  159. // CHECK:STDOUT: %.loc31_17.1: type = value_of_initializer %int.make_type_32.loc31_17 [template = i32]
  160. // CHECK:STDOUT: %.loc31_17.2: type = converted %int.make_type_32.loc31_17, %.loc31_17.1 [template = i32]
  161. // CHECK:STDOUT: %m.param.loc31: i32 = param m, runtime_param1
  162. // CHECK:STDOUT: %m.loc31: i32 = bind_name m, %m.param.loc31
  163. // CHECK:STDOUT: %int.make_type_32.loc31_25: init type = call constants.%Int32() [template = i32]
  164. // CHECK:STDOUT: %.loc31_25.1: type = value_of_initializer %int.make_type_32.loc31_25 [template = i32]
  165. // CHECK:STDOUT: %.loc31_25.2: type = converted %int.make_type_32.loc31_25, %.loc31_25.1 [template = i32]
  166. // CHECK:STDOUT: %return.var.loc31: ref i32 = var <return slot>
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: %C.decl.loc38: %C.type = fn_decl @C [template = constants.%C] {
  169. // CHECK:STDOUT: %n.patt: i32 = binding_pattern n
  170. // CHECK:STDOUT: %m.patt: i32 = binding_pattern m
  171. // CHECK:STDOUT: } {
  172. // CHECK:STDOUT: %int.make_type_32.loc38_9: init type = call constants.%Int32() [template = i32]
  173. // CHECK:STDOUT: %.loc38_9.1: type = value_of_initializer %int.make_type_32.loc38_9 [template = i32]
  174. // CHECK:STDOUT: %.loc38_9.2: type = converted %int.make_type_32.loc38_9, %.loc38_9.1 [template = i32]
  175. // CHECK:STDOUT: %n.param.loc38: i32 = param n, runtime_param0
  176. // CHECK:STDOUT: %n.loc38: i32 = bind_name n, %n.param.loc38
  177. // CHECK:STDOUT: %int.make_type_32.loc38_17: init type = call constants.%Int32() [template = i32]
  178. // CHECK:STDOUT: %.loc38_17.1: type = value_of_initializer %int.make_type_32.loc38_17 [template = i32]
  179. // CHECK:STDOUT: %.loc38_17.2: type = converted %int.make_type_32.loc38_17, %.loc38_17.1 [template = i32]
  180. // CHECK:STDOUT: %m.param.loc38: i32 = param m, runtime_param1
  181. // CHECK:STDOUT: %m.loc38: i32 = bind_name m, %m.param.loc38
  182. // CHECK:STDOUT: %int.make_type_32.loc38_25: init type = call constants.%Int32() [template = i32]
  183. // CHECK:STDOUT: %.loc38_25.1: type = value_of_initializer %int.make_type_32.loc38_25 [template = i32]
  184. // CHECK:STDOUT: %.loc38_25.2: type = converted %int.make_type_32.loc38_25, %.loc38_25.1 [template = i32]
  185. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: fn @A(%n.loc19: i32, %m.loc19: i32) -> i32 = "int.sadd" {
  192. // CHECK:STDOUT: !entry:
  193. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n.loc19
  194. // CHECK:STDOUT: return %n.ref
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: fn @B(%n.loc29: i32, %m.loc29: i32) -> i32 = "int.sadd" {
  198. // CHECK:STDOUT: !entry:
  199. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n.loc21
  200. // CHECK:STDOUT: return %n.ref
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: fn @C(%n.loc38: i32, %m.loc38: i32) -> i32 = "int.sadd";
  204. // CHECK:STDOUT: