fail_duplicate.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/fail_duplicate.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_duplicate.carbon
  14. // --- fail_redefine_without_dependents.carbon
  15. library "[[@TEST_NAME]]";
  16. interface Interface { }
  17. // CHECK:STDERR: fail_redefine_without_dependents.carbon:[[@LINE+7]]:1: error: redefinition of `interface Interface` [RedeclRedef]
  18. // CHECK:STDERR: interface Interface {
  19. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  20. // CHECK:STDERR: fail_redefine_without_dependents.carbon:[[@LINE-5]]:1: note: previously defined here [RedeclPrevDef]
  21. // CHECK:STDERR: interface Interface { }
  22. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  23. // CHECK:STDERR:
  24. interface Interface {
  25. fn F();
  26. }
  27. // --- fail_redefine_with_dependents.carbon
  28. library "[[@TEST_NAME]]";
  29. interface Interface {}
  30. // CHECK:STDERR: fail_redefine_with_dependents.carbon:[[@LINE+7]]:1: error: redefinition of `interface Interface` [RedeclRedef]
  31. // CHECK:STDERR: interface Interface {
  32. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  33. // CHECK:STDERR: fail_redefine_with_dependents.carbon:[[@LINE-5]]:1: note: previously defined here [RedeclPrevDef]
  34. // CHECK:STDERR: interface Interface {}
  35. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  36. // CHECK:STDERR:
  37. interface Interface {
  38. fn F[self: Self]();
  39. }
  40. // --- fail_name_conflict_with_fn.carbon
  41. library "[[@TEST_NAME]]";
  42. fn Function();
  43. // CHECK:STDERR: fail_name_conflict_with_fn.carbon:[[@LINE+7]]:11: error: duplicate name `Function` being declared in the same scope [NameDeclDuplicate]
  44. // CHECK:STDERR: interface Function;
  45. // CHECK:STDERR: ^~~~~~~~
  46. // CHECK:STDERR: fail_name_conflict_with_fn.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious]
  47. // CHECK:STDERR: fn Function();
  48. // CHECK:STDERR: ^~~~~~~~~~~~~~
  49. // CHECK:STDERR:
  50. interface Function;
  51. // --- fail_name_conflict_with_class.carbon
  52. class Class;
  53. // CHECK:STDERR: fail_name_conflict_with_class.carbon:[[@LINE+7]]:11: error: duplicate name `Class` being declared in the same scope [NameDeclDuplicate]
  54. // CHECK:STDERR: interface Class { }
  55. // CHECK:STDERR: ^~~~~
  56. // CHECK:STDERR: fail_name_conflict_with_class.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious]
  57. // CHECK:STDERR: class Class;
  58. // CHECK:STDERR: ^~~~~~~~~~~~
  59. // CHECK:STDERR:
  60. interface Class { }
  61. // CHECK:STDOUT: --- fail_redefine_without_dependents.carbon
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: constants {
  64. // CHECK:STDOUT: %Interface.type.6f2e43.1: type = facet_type <@Interface.loc4> [concrete]
  65. // CHECK:STDOUT: %Self.8875a4.1: %Interface.type.6f2e43.1 = symbolic_binding Self, 0 [symbolic]
  66. // CHECK:STDOUT: %Interface.type.6f2e43.2: type = facet_type <@Interface.loc13> [concrete]
  67. // CHECK:STDOUT: %Self.8875a4.2: %Interface.type.6f2e43.2 = symbolic_binding Self, 0 [symbolic]
  68. // CHECK:STDOUT: %Interface.WithSelf.F.type: type = fn_type @Interface.WithSelf.F, @Interface.WithSelf.loc13(%Self.8875a4.2) [symbolic]
  69. // CHECK:STDOUT: %Interface.WithSelf.F: %Interface.WithSelf.F.type = struct_value () [symbolic]
  70. // CHECK:STDOUT: %Interface.assoc_type: type = assoc_entity_type @Interface.loc13 [concrete]
  71. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, @Interface.WithSelf.loc13.%Interface.WithSelf.F.decl [concrete]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: file {
  75. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  76. // CHECK:STDOUT: .Interface = %Interface.decl.loc4
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %Interface.decl.loc4: type = interface_decl @Interface.loc4 [concrete = constants.%Interface.type.6f2e43.1] {} {}
  79. // CHECK:STDOUT: %Interface.decl.loc13: type = interface_decl @Interface.loc13 [concrete = constants.%Interface.type.6f2e43.2] {} {}
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: interface @Interface.loc4 {
  83. // CHECK:STDOUT: %Self: %Interface.type.6f2e43.1 = symbolic_binding Self, 0 [symbolic = constants.%Self.8875a4.1]
  84. // CHECK:STDOUT: %Interface.WithSelf.decl = interface_with_self_decl @Interface.loc4 [concrete]
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .Self = %Self
  88. // CHECK:STDOUT: witness = ()
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: !requires:
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: interface @Interface.loc13 {
  94. // CHECK:STDOUT: %Self: %Interface.type.6f2e43.2 = symbolic_binding Self, 0 [symbolic = constants.%Self.8875a4.2]
  95. // CHECK:STDOUT: %Interface.WithSelf.decl = interface_with_self_decl @Interface.loc13 [concrete]
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !with Self:
  98. // CHECK:STDOUT: %Interface.WithSelf.F.decl: @Interface.WithSelf.loc13.%Interface.WithSelf.F.type (%Interface.WithSelf.F.type) = fn_decl @Interface.WithSelf.F [symbolic = @Interface.WithSelf.loc13.%Interface.WithSelf.F (constants.%Interface.WithSelf.F)] {} {}
  99. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, %Interface.WithSelf.F.decl [concrete = constants.%assoc0]
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: !members:
  102. // CHECK:STDOUT: .Self = %Self
  103. // CHECK:STDOUT: .F = @Interface.WithSelf.loc13.%assoc0
  104. // CHECK:STDOUT: witness = (@Interface.WithSelf.loc13.%Interface.WithSelf.F.decl)
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: !requires:
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: generic fn @Interface.WithSelf.F(@Interface.loc13.%Self: %Interface.type.6f2e43.2) {
  110. // CHECK:STDOUT: fn();
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: specific @Interface.WithSelf.loc4(constants.%Self.8875a4.1) {}
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: specific @Interface.WithSelf.loc13(constants.%Self.8875a4.2) {}
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: specific @Interface.WithSelf.F(constants.%Self.8875a4.2) {}
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: --- fail_redefine_with_dependents.carbon
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: constants {
  122. // CHECK:STDOUT: %Interface.type.6f2e43.1: type = facet_type <@Interface.loc4> [concrete]
  123. // CHECK:STDOUT: %Self.8875a4.1: %Interface.type.6f2e43.1 = symbolic_binding Self, 0 [symbolic]
  124. // CHECK:STDOUT: %Interface.type.6f2e43.2: type = facet_type <@Interface.loc13> [concrete]
  125. // CHECK:STDOUT: %Self.8875a4.2: %Interface.type.6f2e43.2 = symbolic_binding Self, 0 [symbolic]
  126. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self.8875a4.2 [symbolic]
  127. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic]
  128. // CHECK:STDOUT: %Interface.WithSelf.F.type: type = fn_type @Interface.WithSelf.F, @Interface.WithSelf.loc13(%Self.8875a4.2) [symbolic]
  129. // CHECK:STDOUT: %Interface.WithSelf.F: %Interface.WithSelf.F.type = struct_value () [symbolic]
  130. // CHECK:STDOUT: %Interface.assoc_type: type = assoc_entity_type @Interface.loc13 [concrete]
  131. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, @Interface.WithSelf.loc13.%Interface.WithSelf.F.decl [concrete]
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: file {
  135. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  136. // CHECK:STDOUT: .Interface = %Interface.decl.loc4
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: %Interface.decl.loc4: type = interface_decl @Interface.loc4 [concrete = constants.%Interface.type.6f2e43.1] {} {}
  139. // CHECK:STDOUT: %Interface.decl.loc13: type = interface_decl @Interface.loc13 [concrete = constants.%Interface.type.6f2e43.2] {} {}
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: interface @Interface.loc4 {
  143. // CHECK:STDOUT: %Self: %Interface.type.6f2e43.1 = symbolic_binding Self, 0 [symbolic = constants.%Self.8875a4.1]
  144. // CHECK:STDOUT: %Interface.WithSelf.decl = interface_with_self_decl @Interface.loc4 [concrete]
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: !members:
  147. // CHECK:STDOUT: .Self = %Self
  148. // CHECK:STDOUT: witness = ()
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: !requires:
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: interface @Interface.loc13 {
  154. // CHECK:STDOUT: %Self: %Interface.type.6f2e43.2 = symbolic_binding Self, 0 [symbolic = constants.%Self.8875a4.2]
  155. // CHECK:STDOUT: %Interface.WithSelf.decl = interface_with_self_decl @Interface.loc13 [concrete]
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: !with Self:
  158. // CHECK:STDOUT: %Interface.WithSelf.F.decl: @Interface.WithSelf.loc13.%Interface.WithSelf.F.type (%Interface.WithSelf.F.type) = fn_decl @Interface.WithSelf.F [symbolic = @Interface.WithSelf.loc13.%Interface.WithSelf.F (constants.%Interface.WithSelf.F)] {
  159. // CHECK:STDOUT: %self.param_patt: @Interface.WithSelf.F.%pattern_type (%pattern_type) = value_param_pattern [concrete]
  160. // CHECK:STDOUT: %self.patt: @Interface.WithSelf.F.%pattern_type (%pattern_type) = at_binding_pattern self, %self.param_patt [concrete]
  161. // CHECK:STDOUT: } {
  162. // CHECK:STDOUT: %self.param: @Interface.WithSelf.F.%Self.binding.as_type (%Self.binding.as_type) = value_param call_param0
  163. // CHECK:STDOUT: %.loc14_14.1: type = splice_block %.loc14_14.2 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)] {
  164. // CHECK:STDOUT: %Self.ref: %Interface.type.6f2e43.2 = name_ref Self, @Interface.loc13.%Self [symbolic = %Self (constants.%Self.8875a4.2)]
  165. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self.ref [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  166. // CHECK:STDOUT: %.loc14_14.2: type = converted %Self.ref, %Self.as_type [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: %self: @Interface.WithSelf.F.%Self.binding.as_type (%Self.binding.as_type) = value_binding self, %self.param
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, %Interface.WithSelf.F.decl [concrete = constants.%assoc0]
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: !members:
  173. // CHECK:STDOUT: .Self = %Self
  174. // CHECK:STDOUT: .F = @Interface.WithSelf.loc13.%assoc0
  175. // CHECK:STDOUT: witness = (@Interface.WithSelf.loc13.%Interface.WithSelf.F.decl)
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: !requires:
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: generic fn @Interface.WithSelf.F(@Interface.loc13.%Self: %Interface.type.6f2e43.2) {
  181. // CHECK:STDOUT: %Self: %Interface.type.6f2e43.2 = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self.8875a4.2)]
  182. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  183. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic = %pattern_type (constants.%pattern_type)]
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: fn(%self.param: @Interface.WithSelf.F.%Self.binding.as_type (%Self.binding.as_type));
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: specific @Interface.WithSelf.loc4(constants.%Self.8875a4.1) {}
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: specific @Interface.WithSelf.loc13(constants.%Self.8875a4.2) {}
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: specific @Interface.WithSelf.F(constants.%Self.8875a4.2) {
  193. // CHECK:STDOUT: %Self => constants.%Self.8875a4.2
  194. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  195. // CHECK:STDOUT: %pattern_type => constants.%pattern_type
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: --- fail_name_conflict_with_fn.carbon
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: constants {
  201. // CHECK:STDOUT: %Function.type.7c0: type = fn_type @Function.loc4 [concrete]
  202. // CHECK:STDOUT: %Function: %Function.type.7c0 = struct_value () [concrete]
  203. // CHECK:STDOUT: %Function.type.1b7: type = facet_type <@Function.loc13> [concrete]
  204. // CHECK:STDOUT: }
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: file {
  207. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  208. // CHECK:STDOUT: .Function = %Function.decl.loc4
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT: %Function.decl.loc4: %Function.type.7c0 = fn_decl @Function.loc4 [concrete = constants.%Function] {} {}
  211. // CHECK:STDOUT: %Function.decl.loc13: type = interface_decl @Function.loc13 [concrete = constants.%Function.type.1b7] {} {}
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: interface @Function.loc13;
  215. // CHECK:STDOUT:
  216. // CHECK:STDOUT: fn @Function.loc4();
  217. // CHECK:STDOUT:
  218. // CHECK:STDOUT: --- fail_name_conflict_with_class.carbon
  219. // CHECK:STDOUT:
  220. // CHECK:STDOUT: constants {
  221. // CHECK:STDOUT: %Class: type = class_type @Class.loc2 [concrete]
  222. // CHECK:STDOUT: %Class.type: type = facet_type <@Class.loc11> [concrete]
  223. // CHECK:STDOUT: %Self: %Class.type = symbolic_binding Self, 0 [symbolic]
  224. // CHECK:STDOUT: }
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: file {
  227. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  228. // CHECK:STDOUT: .Class = %Class.decl.loc2
  229. // CHECK:STDOUT: }
  230. // CHECK:STDOUT: %Class.decl.loc2: type = class_decl @Class.loc2 [concrete = constants.%Class] {} {}
  231. // CHECK:STDOUT: %Class.decl.loc11: type = interface_decl @Class.loc11 [concrete = constants.%Class.type] {} {}
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: interface @Class.loc11 {
  235. // CHECK:STDOUT: %Self: %Class.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  236. // CHECK:STDOUT: %Class.WithSelf.decl = interface_with_self_decl @Class.loc11 [concrete]
  237. // CHECK:STDOUT:
  238. // CHECK:STDOUT: !members:
  239. // CHECK:STDOUT: .Self = %Self
  240. // CHECK:STDOUT: witness = ()
  241. // CHECK:STDOUT:
  242. // CHECK:STDOUT: !requires:
  243. // CHECK:STDOUT: }
  244. // CHECK:STDOUT:
  245. // CHECK:STDOUT: class @Class.loc2;
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: specific @Class.WithSelf(constants.%Self) {}
  248. // CHECK:STDOUT: