fail_duplicate.carbon 9.2 KB

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