fail_duplicate.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.d726c6.1: type = facet_type <@Interface.loc4> [concrete]
  65. // CHECK:STDOUT: %Self.719cbb.1: %Interface.type.d726c6.1 = bind_symbolic_name Self, 0 [symbolic]
  66. // CHECK:STDOUT: %Interface.type.d726c6.2: type = facet_type <@Interface.loc13> [concrete]
  67. // CHECK:STDOUT: %Self.719cbb.2: %Interface.type.d726c6.2 = bind_symbolic_name Self, 0 [symbolic]
  68. // CHECK:STDOUT: %Interface.F.type: type = fn_type @Interface.F [concrete]
  69. // CHECK:STDOUT: %Interface.F: %Interface.F.type = struct_value () [concrete]
  70. // CHECK:STDOUT: %Interface.assoc_type: type = assoc_entity_type @Interface.loc13 [concrete]
  71. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, @Interface.loc13.%Interface.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.d726c6.1] {} {}
  79. // CHECK:STDOUT: %Interface.decl.loc13: type = interface_decl @Interface.loc13 [concrete = constants.%Interface.type.d726c6.2] {} {}
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: interface @Interface.loc4 {
  83. // CHECK:STDOUT: %Self: %Interface.type.d726c6.1 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.719cbb.1]
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: !members:
  86. // CHECK:STDOUT: .Self = %Self
  87. // CHECK:STDOUT: witness = ()
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: interface @Interface.loc13 {
  91. // CHECK:STDOUT: %Self: %Interface.type.d726c6.2 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.719cbb.2]
  92. // CHECK:STDOUT: %Interface.F.decl: %Interface.F.type = fn_decl @Interface.F [concrete = constants.%Interface.F] {} {}
  93. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, %Interface.F.decl [concrete = constants.%assoc0]
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: !members:
  96. // CHECK:STDOUT: .Self = %Self
  97. // CHECK:STDOUT: .F = %assoc0
  98. // CHECK:STDOUT: witness = (%Interface.F.decl)
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: generic fn @Interface.F(@Interface.loc13.%Self: %Interface.type.d726c6.2) {
  102. // CHECK:STDOUT: fn();
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: specific @Interface.F(constants.%Self.719cbb.2) {}
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: --- fail_redefine_with_dependents.carbon
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: constants {
  110. // CHECK:STDOUT: %Interface.type.d726c6.1: type = facet_type <@Interface.loc4> [concrete]
  111. // CHECK:STDOUT: %Self.719cbb.1: %Interface.type.d726c6.1 = bind_symbolic_name Self, 0 [symbolic]
  112. // CHECK:STDOUT: %Interface.type.d726c6.2: type = facet_type <@Interface.loc13> [concrete]
  113. // CHECK:STDOUT: %Self.719cbb.2: %Interface.type.d726c6.2 = bind_symbolic_name Self, 0 [symbolic]
  114. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self.719cbb.2 [symbolic]
  115. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type [symbolic]
  116. // CHECK:STDOUT: %Interface.F.type: type = fn_type @Interface.F [concrete]
  117. // CHECK:STDOUT: %Interface.F: %Interface.F.type = struct_value () [concrete]
  118. // CHECK:STDOUT: %Interface.assoc_type: type = assoc_entity_type @Interface.loc13 [concrete]
  119. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, @Interface.loc13.%Interface.F.decl [concrete]
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: file {
  123. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  124. // CHECK:STDOUT: .Interface = %Interface.decl.loc4
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %Interface.decl.loc4: type = interface_decl @Interface.loc4 [concrete = constants.%Interface.type.d726c6.1] {} {}
  127. // CHECK:STDOUT: %Interface.decl.loc13: type = interface_decl @Interface.loc13 [concrete = constants.%Interface.type.d726c6.2] {} {}
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: interface @Interface.loc4 {
  131. // CHECK:STDOUT: %Self: %Interface.type.d726c6.1 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.719cbb.1]
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: !members:
  134. // CHECK:STDOUT: .Self = %Self
  135. // CHECK:STDOUT: witness = ()
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: interface @Interface.loc13 {
  139. // CHECK:STDOUT: %Self: %Interface.type.d726c6.2 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.719cbb.2]
  140. // CHECK:STDOUT: %Interface.F.decl: %Interface.F.type = fn_decl @Interface.F [concrete = constants.%Interface.F] {
  141. // CHECK:STDOUT: %self.patt: @Interface.F.%pattern_type (%pattern_type) = binding_pattern self [concrete]
  142. // CHECK:STDOUT: %self.param_patt: @Interface.F.%pattern_type (%pattern_type) = value_param_pattern %self.patt, call_param0 [concrete]
  143. // CHECK:STDOUT: } {
  144. // CHECK:STDOUT: %self.param: @Interface.F.%Self.as_type.loc14_14.1 (%Self.as_type) = value_param call_param0
  145. // CHECK:STDOUT: %.loc14_14.1: type = splice_block %.loc14_14.2 [symbolic = %Self.as_type.loc14_14.1 (constants.%Self.as_type)] {
  146. // CHECK:STDOUT: %Self.ref: %Interface.type.d726c6.2 = name_ref Self, @Interface.loc13.%Self [symbolic = %Self (constants.%Self.719cbb.2)]
  147. // CHECK:STDOUT: %Self.as_type.loc14_14.2: type = facet_access_type %Self.ref [symbolic = %Self.as_type.loc14_14.1 (constants.%Self.as_type)]
  148. // CHECK:STDOUT: %.loc14_14.2: type = converted %Self.ref, %Self.as_type.loc14_14.2 [symbolic = %Self.as_type.loc14_14.1 (constants.%Self.as_type)]
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: %self: @Interface.F.%Self.as_type.loc14_14.1 (%Self.as_type) = bind_name self, %self.param
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, %Interface.F.decl [concrete = constants.%assoc0]
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: !members:
  155. // CHECK:STDOUT: .Self = %Self
  156. // CHECK:STDOUT: .F = %assoc0
  157. // CHECK:STDOUT: witness = (%Interface.F.decl)
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: generic fn @Interface.F(@Interface.loc13.%Self: %Interface.type.d726c6.2) {
  161. // CHECK:STDOUT: %Self: %Interface.type.d726c6.2 = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self.719cbb.2)]
  162. // CHECK:STDOUT: %Self.as_type.loc14_14.1: type = facet_access_type %Self [symbolic = %Self.as_type.loc14_14.1 (constants.%Self.as_type)]
  163. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type.loc14_14.1 [symbolic = %pattern_type (constants.%pattern_type)]
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: fn(%self.param: @Interface.F.%Self.as_type.loc14_14.1 (%Self.as_type));
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: specific @Interface.F(constants.%Self.719cbb.2) {
  169. // CHECK:STDOUT: %Self => constants.%Self.719cbb.2
  170. // CHECK:STDOUT: %Self.as_type.loc14_14.1 => constants.%Self.as_type
  171. // CHECK:STDOUT: %pattern_type => constants.%pattern_type
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: --- fail_name_conflict_with_fn.carbon
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: constants {
  177. // CHECK:STDOUT: %Function.type.b14: type = fn_type @Function.loc4 [concrete]
  178. // CHECK:STDOUT: %Function: %Function.type.b14 = struct_value () [concrete]
  179. // CHECK:STDOUT: %Function.type.f90: type = facet_type <@Function.loc13> [concrete]
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: file {
  183. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  184. // CHECK:STDOUT: .Function = %Function.decl.loc4
  185. // CHECK:STDOUT: }
  186. // CHECK:STDOUT: %Function.decl.loc4: %Function.type.b14 = fn_decl @Function.loc4 [concrete = constants.%Function] {} {}
  187. // CHECK:STDOUT: %Function.decl.loc13: type = interface_decl @Function.loc13 [concrete = constants.%Function.type.f90] {} {}
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: interface @Function.loc13;
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: fn @Function.loc4();
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: --- fail_name_conflict_with_class.carbon
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: constants {
  197. // CHECK:STDOUT: %Class: type = class_type @Class.loc2 [concrete]
  198. // CHECK:STDOUT: %Class.type: type = facet_type <@Class.loc11> [concrete]
  199. // CHECK:STDOUT: %Self: %Class.type = bind_symbolic_name Self, 0 [symbolic]
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: file {
  203. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  204. // CHECK:STDOUT: .Class = %Class.decl.loc2
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT: %Class.decl.loc2: type = class_decl @Class.loc2 [concrete = constants.%Class] {} {}
  207. // CHECK:STDOUT: %Class.decl.loc11: type = interface_decl @Class.loc11 [concrete = constants.%Class.type] {} {}
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: interface @Class.loc11 {
  211. // CHECK:STDOUT: %Self: %Class.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: !members:
  214. // CHECK:STDOUT: .Self = %Self
  215. // CHECK:STDOUT: witness = ()
  216. // CHECK:STDOUT: }
  217. // CHECK:STDOUT:
  218. // CHECK:STDOUT: class @Class.loc2;
  219. // CHECK:STDOUT: