fail_duplicate.carbon 11 KB

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