redeclare.carbon 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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/class/generic/redeclare.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/redeclare.carbon
  10. // --- valid.carbon
  11. library "valid";
  12. class Generic(T:! type);
  13. class Generic(T:! type) {
  14. }
  15. // --- fail_mismatch_param_list.carbon
  16. library "mismatch_param_list";
  17. class A;
  18. // CHECK:STDERR: fail_mismatch_param_list.carbon:[[@LINE+7]]:1: ERROR: Redeclaration differs because of parameter list.
  19. // CHECK:STDERR: class A(T:! type) {}
  20. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
  21. // CHECK:STDERR: fail_mismatch_param_list.carbon:[[@LINE-4]]:1: Previously declared without parameter list.
  22. // CHECK:STDERR: class A;
  23. // CHECK:STDERR: ^~~~~~~~
  24. // CHECK:STDERR:
  25. class A(T:! type) {}
  26. // --- fail_mismatch_implicit_param_list.carbon
  27. library "implicit_mismatch_param_list";
  28. class B(N:! i32);
  29. // CHECK:STDERR: fail_mismatch_implicit_param_list.carbon:[[@LINE+7]]:1: ERROR: Redeclaration differs because of implicit parameter list.
  30. // CHECK:STDERR: class B[T:! type](N:! T) {}
  31. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~
  32. // CHECK:STDERR: fail_mismatch_implicit_param_list.carbon:[[@LINE-4]]:1: Previously declared without implicit parameter list.
  33. // CHECK:STDERR: class B(N:! i32);
  34. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  35. // CHECK:STDERR:
  36. class B[T:! type](N:! T) {}
  37. // --- fail_mismatch_param_count.carbon
  38. library "mismatch_param_count";
  39. class C(T:! type);
  40. // CHECK:STDERR: fail_mismatch_param_count.carbon:[[@LINE+7]]:1: ERROR: Redeclaration differs because of parameter count of 2.
  41. // CHECK:STDERR: class C(T:! type, U:! i32) {}
  42. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. // CHECK:STDERR: fail_mismatch_param_count.carbon:[[@LINE-4]]:1: Previously declared with parameter count of 1.
  44. // CHECK:STDERR: class C(T:! type);
  45. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  46. // CHECK:STDERR:
  47. class C(T:! type, U:! i32) {}
  48. // --- fail_mismatch_param_type.carbon
  49. library "mismatch_param_type";
  50. class D(T:! type);
  51. // CHECK:STDERR: fail_mismatch_param_type.carbon:[[@LINE+7]]:9: ERROR: Redeclaration differs at parameter 1.
  52. // CHECK:STDERR: class D(T:! i32) {}
  53. // CHECK:STDERR: ^
  54. // CHECK:STDERR: fail_mismatch_param_type.carbon:[[@LINE-4]]:9: Previous declaration's corresponding parameter here.
  55. // CHECK:STDERR: class D(T:! type);
  56. // CHECK:STDERR: ^
  57. // CHECK:STDERR:
  58. class D(T:! i32) {}
  59. // --- fail_mismatch_param_name.carbon
  60. library "mismatch_param_name";
  61. class E(T:! type);
  62. // CHECK:STDERR: fail_mismatch_param_name.carbon:[[@LINE+6]]:9: ERROR: Redeclaration differs at parameter 1.
  63. // CHECK:STDERR: class E(U:! type) {}
  64. // CHECK:STDERR: ^
  65. // CHECK:STDERR: fail_mismatch_param_name.carbon:[[@LINE-4]]:9: Previous declaration's corresponding parameter here.
  66. // CHECK:STDERR: class E(T:! type);
  67. // CHECK:STDERR: ^
  68. class E(U:! type) {}
  69. // CHECK:STDOUT: --- valid.carbon
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: constants {
  72. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  73. // CHECK:STDOUT: %Generic.type: type = generic_class_type @Generic [template]
  74. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  75. // CHECK:STDOUT: %Generic.1: %Generic.type = struct_value () [template]
  76. // CHECK:STDOUT: %Generic.2: type = class_type @Generic, (%T) [symbolic]
  77. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: file {
  81. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  82. // CHECK:STDOUT: .Core = %Core
  83. // CHECK:STDOUT: .Generic = %Generic.decl.loc4
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  86. // CHECK:STDOUT: %Generic.decl.loc4: %Generic.type = class_decl @Generic [template = constants.%Generic.1] {
  87. // CHECK:STDOUT: %T.loc4_15.1: type = param T
  88. // CHECK:STDOUT: %T.loc4_15.2: type = bind_symbolic_name T 0, %T.loc4_15.1 [symbolic = constants.%T]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %Generic.decl.loc6: %Generic.type = class_decl @Generic [template = constants.%Generic.1] {
  91. // CHECK:STDOUT: %T.loc6_15.1: type = param T
  92. // CHECK:STDOUT: %T.loc6_15.2: type = bind_symbolic_name T 0, %T.loc6_15.1 [symbolic = constants.%T]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: class @Generic
  97. // CHECK:STDOUT: generic [file.%T.loc4_15.2: type] {
  98. // CHECK:STDOUT: !members:
  99. // CHECK:STDOUT: .Self = constants.%Generic.2
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: --- fail_mismatch_param_list.carbon
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: constants {
  105. // CHECK:STDOUT: %A: type = class_type @A [template]
  106. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  107. // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
  108. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  109. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  110. // CHECK:STDOUT: %.3: type = class_type @.1, (%T) [symbolic]
  111. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: file {
  115. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  116. // CHECK:STDOUT: .Core = %Core
  117. // CHECK:STDOUT: .A = %A.decl
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  120. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  121. // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
  122. // CHECK:STDOUT: %T.loc12_9.1: type = param T
  123. // CHECK:STDOUT: %T.loc12_9.2: type = bind_symbolic_name T 0, %T.loc12_9.1 [symbolic = constants.%T]
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: class @A;
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: class @.1
  130. // CHECK:STDOUT: generic [file.%T.loc12_9.2: type] {
  131. // CHECK:STDOUT: !members:
  132. // CHECK:STDOUT: .Self = constants.%.3
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: --- fail_mismatch_implicit_param_list.carbon
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: constants {
  138. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  139. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  140. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  141. // CHECK:STDOUT: %N.1: i32 = bind_symbolic_name N 0 [symbolic]
  142. // CHECK:STDOUT: %B.type: type = generic_class_type @B [template]
  143. // CHECK:STDOUT: %B.1: %B.type = struct_value () [template]
  144. // CHECK:STDOUT: %B.2: type = class_type @B, (%N.1) [symbolic]
  145. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  146. // CHECK:STDOUT: %N.2: %T = bind_symbolic_name N 1 [symbolic]
  147. // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
  148. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  149. // CHECK:STDOUT: %.3: type = class_type @.1, (%T, %N.2) [symbolic]
  150. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: file {
  154. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  155. // CHECK:STDOUT: .Core = %Core
  156. // CHECK:STDOUT: .B = %B.decl
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  159. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  160. // CHECK:STDOUT: %B.decl: %B.type = class_decl @B [template = constants.%B.1] {
  161. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  162. // CHECK:STDOUT: %.loc4_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  163. // CHECK:STDOUT: %.loc4_13.2: type = converted %int.make_type_32, %.loc4_13.1 [template = i32]
  164. // CHECK:STDOUT: %N.loc4_9.1: i32 = param N
  165. // CHECK:STDOUT: %N.loc4_9.2: i32 = bind_symbolic_name N 0, %N.loc4_9.1 [symbolic = constants.%N.1]
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
  168. // CHECK:STDOUT: %T.loc12_9.1: type = param T
  169. // CHECK:STDOUT: %T.loc12_9.2: type = bind_symbolic_name T 0, %T.loc12_9.1 [symbolic = constants.%T]
  170. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc12_9.2 [symbolic = constants.%T]
  171. // CHECK:STDOUT: %N.loc12_19.1: %T = param N
  172. // CHECK:STDOUT: %N.loc12_19.2: %T = bind_symbolic_name N 1, %N.loc12_19.1 [symbolic = constants.%N.2]
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: class @B
  177. // CHECK:STDOUT: generic [file.%N.loc4_9.2: i32];
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: class @.1
  180. // CHECK:STDOUT: generic [file.%T.loc12_9.2: type, file.%N.loc12_19.2: %T] {
  181. // CHECK:STDOUT: !members:
  182. // CHECK:STDOUT: .Self = constants.%.3
  183. // CHECK:STDOUT: }
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: --- fail_mismatch_param_count.carbon
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: constants {
  190. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  191. // CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
  192. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  193. // CHECK:STDOUT: %C.1: %C.type = struct_value () [template]
  194. // CHECK:STDOUT: %C.2: type = class_type @C, (%T) [symbolic]
  195. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  196. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  197. // CHECK:STDOUT: %U: i32 = bind_symbolic_name U 1 [symbolic]
  198. // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
  199. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  200. // CHECK:STDOUT: %.3: type = class_type @.1, (%T, %U) [symbolic]
  201. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: file {
  205. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  206. // CHECK:STDOUT: .Core = %Core
  207. // CHECK:STDOUT: .C = %C.decl
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  210. // CHECK:STDOUT: %C.decl: %C.type = class_decl @C [template = constants.%C.1] {
  211. // CHECK:STDOUT: %T.loc4_9.1: type = param T
  212. // CHECK:STDOUT: %T.loc4_9.2: type = bind_symbolic_name T 0, %T.loc4_9.1 [symbolic = constants.%T]
  213. // CHECK:STDOUT: }
  214. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  215. // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
  216. // CHECK:STDOUT: %T.loc12_9.1: type = param T
  217. // CHECK:STDOUT: %T.loc12_9.2: type = bind_symbolic_name T 0, %T.loc12_9.1 [symbolic = constants.%T]
  218. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  219. // CHECK:STDOUT: %.loc12_23.1: type = value_of_initializer %int.make_type_32 [template = i32]
  220. // CHECK:STDOUT: %.loc12_23.2: type = converted %int.make_type_32, %.loc12_23.1 [template = i32]
  221. // CHECK:STDOUT: %U.loc12_19.1: i32 = param U
  222. // CHECK:STDOUT: %U.loc12_19.2: i32 = bind_symbolic_name U 1, %U.loc12_19.1 [symbolic = constants.%U]
  223. // CHECK:STDOUT: }
  224. // CHECK:STDOUT: }
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: class @C
  227. // CHECK:STDOUT: generic [file.%T.loc4_9.2: type];
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: class @.1
  230. // CHECK:STDOUT: generic [file.%T.loc12_9.2: type, file.%U.loc12_19.2: i32] {
  231. // CHECK:STDOUT: !members:
  232. // CHECK:STDOUT: .Self = constants.%.3
  233. // CHECK:STDOUT: }
  234. // CHECK:STDOUT:
  235. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: --- fail_mismatch_param_type.carbon
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: constants {
  240. // CHECK:STDOUT: %T.1: type = bind_symbolic_name T 0 [symbolic]
  241. // CHECK:STDOUT: %D.type: type = generic_class_type @D [template]
  242. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  243. // CHECK:STDOUT: %D.1: %D.type = struct_value () [template]
  244. // CHECK:STDOUT: %D.2: type = class_type @D, (%T.1) [symbolic]
  245. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  246. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  247. // CHECK:STDOUT: %T.2: i32 = bind_symbolic_name T 0 [symbolic]
  248. // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
  249. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  250. // CHECK:STDOUT: %.3: type = class_type @.1, (%T.2) [symbolic]
  251. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  252. // CHECK:STDOUT: }
  253. // CHECK:STDOUT:
  254. // CHECK:STDOUT: file {
  255. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  256. // CHECK:STDOUT: .Core = %Core
  257. // CHECK:STDOUT: .D = %D.decl
  258. // CHECK:STDOUT: }
  259. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  260. // CHECK:STDOUT: %D.decl: %D.type = class_decl @D [template = constants.%D.1] {
  261. // CHECK:STDOUT: %T.loc4_9.1: type = param T
  262. // CHECK:STDOUT: %T.loc4_9.2: type = bind_symbolic_name T 0, %T.loc4_9.1 [symbolic = constants.%T.1]
  263. // CHECK:STDOUT: }
  264. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  265. // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
  266. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  267. // CHECK:STDOUT: %.loc12_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  268. // CHECK:STDOUT: %.loc12_13.2: type = converted %int.make_type_32, %.loc12_13.1 [template = i32]
  269. // CHECK:STDOUT: %T.loc12_9.1: i32 = param T
  270. // CHECK:STDOUT: %T.loc12_9.2: i32 = bind_symbolic_name T 0, %T.loc12_9.1 [symbolic = constants.%T.2]
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT:
  274. // CHECK:STDOUT: class @D
  275. // CHECK:STDOUT: generic [file.%T.loc4_9.2: type];
  276. // CHECK:STDOUT:
  277. // CHECK:STDOUT: class @.1
  278. // CHECK:STDOUT: generic [file.%T.loc12_9.2: i32] {
  279. // CHECK:STDOUT: !members:
  280. // CHECK:STDOUT: .Self = constants.%.3
  281. // CHECK:STDOUT: }
  282. // CHECK:STDOUT:
  283. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  284. // CHECK:STDOUT:
  285. // CHECK:STDOUT: --- fail_mismatch_param_name.carbon
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: constants {
  288. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  289. // CHECK:STDOUT: %E.type: type = generic_class_type @E [template]
  290. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  291. // CHECK:STDOUT: %E.1: %E.type = struct_value () [template]
  292. // CHECK:STDOUT: %E.2: type = class_type @E, (%T) [symbolic]
  293. // CHECK:STDOUT: %U: type = bind_symbolic_name U 0 [symbolic]
  294. // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
  295. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  296. // CHECK:STDOUT: %.3: type = class_type @.1, (%U) [symbolic]
  297. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  298. // CHECK:STDOUT: }
  299. // CHECK:STDOUT:
  300. // CHECK:STDOUT: file {
  301. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  302. // CHECK:STDOUT: .Core = %Core
  303. // CHECK:STDOUT: .E = %E.decl
  304. // CHECK:STDOUT: }
  305. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  306. // CHECK:STDOUT: %E.decl: %E.type = class_decl @E [template = constants.%E.1] {
  307. // CHECK:STDOUT: %T.loc4_9.1: type = param T
  308. // CHECK:STDOUT: %T.loc4_9.2: type = bind_symbolic_name T 0, %T.loc4_9.1 [symbolic = constants.%T]
  309. // CHECK:STDOUT: }
  310. // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
  311. // CHECK:STDOUT: %U.loc11_9.1: type = param U
  312. // CHECK:STDOUT: %U.loc11_9.2: type = bind_symbolic_name U 0, %U.loc11_9.1 [symbolic = constants.%U]
  313. // CHECK:STDOUT: }
  314. // CHECK:STDOUT: }
  315. // CHECK:STDOUT:
  316. // CHECK:STDOUT: class @E
  317. // CHECK:STDOUT: generic [file.%T.loc4_9.2: type];
  318. // CHECK:STDOUT:
  319. // CHECK:STDOUT: class @.1
  320. // CHECK:STDOUT: generic [file.%U.loc11_9.2: type] {
  321. // CHECK:STDOUT: !members:
  322. // CHECK:STDOUT: .Self = constants.%.3
  323. // CHECK:STDOUT: }
  324. // CHECK:STDOUT: