fail_undefined_interface.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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/impl/fail_undefined_interface.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/fail_undefined_interface.carbon
  14. // --- fail_empty_struct.carbon
  15. library "[[@TEST_NAME]]";
  16. interface I;
  17. // CHECK:STDERR: fail_empty_struct.carbon:[[@LINE+7]]:1: error: definition of impl as incomplete facet type `I` [ImplAsIncompleteFacetTypeDefinition]
  18. // CHECK:STDERR: impl {} as I {}
  19. // CHECK:STDERR: ^~~~~~~~~~~~~~
  20. // CHECK:STDERR: fail_empty_struct.carbon:[[@LINE-4]]:1: note: interface was forward declared here [InterfaceForwardDeclaredHere]
  21. // CHECK:STDERR: interface I;
  22. // CHECK:STDERR: ^~~~~~~~~~~~
  23. // CHECK:STDERR:
  24. impl {} as I {}
  25. // --- fail_class.carbon
  26. library "[[@TEST_NAME]]";
  27. interface J;
  28. class C {}
  29. // CHECK:STDERR: fail_class.carbon:[[@LINE+7]]:1: error: definition of impl as incomplete facet type `J` [ImplAsIncompleteFacetTypeDefinition]
  30. // CHECK:STDERR: impl C as J {}
  31. // CHECK:STDERR: ^~~~~~~~~~~~~
  32. // CHECK:STDERR: fail_class.carbon:[[@LINE-5]]:1: note: interface was forward declared here [InterfaceForwardDeclaredHere]
  33. // CHECK:STDERR: interface J;
  34. // CHECK:STDERR: ^~~~~~~~~~~~
  35. // CHECK:STDERR:
  36. impl C as J {}
  37. // --- fail_incomplete_where.carbon
  38. library "[[@TEST_NAME]]";
  39. class C {}
  40. interface I {}
  41. interface Incomplete;
  42. // CHECK:STDERR: fail_incomplete_where.carbon:[[@LINE+7]]:1: error: definition of impl as incomplete facet type `I where .Self impls Incomplete` [ImplAsIncompleteFacetTypeDefinition]
  43. // CHECK:STDERR: impl C as I where .Self impls Incomplete {}
  44. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. // CHECK:STDERR: fail_incomplete_where.carbon:[[@LINE-5]]:1: note: interface was forward declared here [InterfaceForwardDeclaredHere]
  46. // CHECK:STDERR: interface Incomplete;
  47. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  48. // CHECK:STDERR:
  49. impl C as I where .Self impls Incomplete {}
  50. // --- fail_declaration_incomplete_where_rewrite.carbon
  51. library "[[@TEST_NAME]]";
  52. class C {}
  53. interface J { let T:! type; }
  54. interface Incomplete;
  55. // CHECK:STDERR: fail_declaration_incomplete_where_rewrite.carbon:[[@LINE+7]]:1: error: declaration of impl as incomplete facet type `J where .Self impls Incomplete and .(J.T) = ()` with rewrites [ImplAsIncompleteFacetTypeRewrites]
  56. // CHECK:STDERR: impl C as J where .Self impls Incomplete and .T = ();
  57. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. // CHECK:STDERR: fail_declaration_incomplete_where_rewrite.carbon:[[@LINE-5]]:1: note: interface was forward declared here [InterfaceForwardDeclaredHere]
  59. // CHECK:STDERR: interface Incomplete;
  60. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  61. // CHECK:STDERR:
  62. impl C as J where .Self impls Incomplete and .T = ();
  63. // CHECK:STDOUT: --- fail_empty_struct.carbon
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: constants {
  66. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  67. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  68. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: file {
  72. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  73. // CHECK:STDOUT: .I = %I.decl
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  76. // CHECK:STDOUT: impl_decl @empty_struct_type.as.I.impl [concrete] {} {
  77. // CHECK:STDOUT: %.loc12_7.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  78. // CHECK:STDOUT: %.loc12_7.2: type = converted %.loc12_7.1, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  79. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: interface @I;
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: impl @empty_struct_type.as.I.impl: %.loc12_7.2 as %I.ref {
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: witness = <error>
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: --- fail_class.carbon
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: constants {
  93. // CHECK:STDOUT: %J.type: type = facet_type <@J> [concrete]
  94. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  95. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  96. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: file {
  100. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  101. // CHECK:STDOUT: .J = %J.decl
  102. // CHECK:STDOUT: .C = %C.decl
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %J.decl: type = interface_decl @J [concrete = constants.%J.type] {} {}
  105. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  106. // CHECK:STDOUT: impl_decl @C.as.J.impl [concrete] {} {
  107. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  108. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [concrete = constants.%J.type]
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: interface @J;
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: impl @C.as.J.impl: %C.ref as %J.ref {
  115. // CHECK:STDOUT: !members:
  116. // CHECK:STDOUT: witness = <error>
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: class @C {
  120. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  121. // CHECK:STDOUT: complete_type_witness = %complete_type
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: !members:
  124. // CHECK:STDOUT: .Self = constants.%C
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: --- fail_incomplete_where.carbon
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: constants {
  130. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  131. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  132. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  133. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  134. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic]
  135. // CHECK:STDOUT: %Incomplete.type: type = facet_type <@Incomplete> [concrete]
  136. // CHECK:STDOUT: %.Self: %I.type = symbolic_binding .Self [symbolic_self]
  137. // CHECK:STDOUT: %.Self.binding.as_type: type = symbolic_binding_type .Self, %.Self [symbolic_self]
  138. // CHECK:STDOUT: %I_where.type: type = facet_type <@I where .Self impls @Incomplete> [concrete]
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: file {
  142. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  143. // CHECK:STDOUT: .C = %C.decl
  144. // CHECK:STDOUT: .I = %I.decl
  145. // CHECK:STDOUT: .Incomplete = %Incomplete.decl
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  148. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  149. // CHECK:STDOUT: %Incomplete.decl: type = interface_decl @Incomplete [concrete = constants.%Incomplete.type] {} {}
  150. // CHECK:STDOUT: impl_decl @C.as.I.impl [concrete] {} {
  151. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  152. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  153. // CHECK:STDOUT: %.Self: %I.type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  154. // CHECK:STDOUT: %.Self.ref: %I.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  155. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, file.%Incomplete.decl [concrete = constants.%Incomplete.type]
  156. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self.ref [symbolic_self = constants.%.Self.binding.as_type]
  157. // CHECK:STDOUT: %.loc15_19: type = converted %.Self.ref, %.Self.as_type [symbolic_self = constants.%.Self.binding.as_type]
  158. // CHECK:STDOUT: %.loc15_13: type = where_expr %.Self [concrete = constants.%I_where.type] {
  159. // CHECK:STDOUT: requirement_base_facet_type constants.%I.type
  160. // CHECK:STDOUT: requirement_impls %.loc15_19, %Incomplete.ref
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: interface @I {
  166. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: !members:
  169. // CHECK:STDOUT: .Self = %Self
  170. // CHECK:STDOUT: witness = ()
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: !requires:
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: interface @Incomplete;
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: impl @C.as.I.impl: %C.ref as %.loc15_13 {
  178. // CHECK:STDOUT: !members:
  179. // CHECK:STDOUT: witness = <error>
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: class @C {
  183. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  184. // CHECK:STDOUT: complete_type_witness = %complete_type
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: !members:
  187. // CHECK:STDOUT: .Self = constants.%C
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: --- fail_declaration_incomplete_where_rewrite.carbon
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: constants {
  193. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  194. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  195. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  196. // CHECK:STDOUT: %J.type: type = facet_type <@J> [concrete]
  197. // CHECK:STDOUT: %Self: %J.type = symbolic_binding Self, 0 [symbolic]
  198. // CHECK:STDOUT: %J.assoc_type: type = assoc_entity_type @J [concrete]
  199. // CHECK:STDOUT: %assoc0: %J.assoc_type = assoc_entity element0, @J.%T [concrete]
  200. // CHECK:STDOUT: %Incomplete.type: type = facet_type <@Incomplete> [concrete]
  201. // CHECK:STDOUT: %.Self: %J.type = symbolic_binding .Self [symbolic_self]
  202. // CHECK:STDOUT: %.Self.binding.as_type: type = symbolic_binding_type .Self, %.Self [symbolic_self]
  203. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  204. // CHECK:STDOUT: %J.lookup_impl_witness: <witness> = lookup_impl_witness %.Self, @J [symbolic_self]
  205. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access %J.lookup_impl_witness, element0 [symbolic_self]
  206. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  207. // CHECK:STDOUT: %J_where.type: type = facet_type <@J where .Self impls @Incomplete and %impl.elem0 = %empty_tuple.type> [concrete]
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: file {
  211. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  212. // CHECK:STDOUT: .C = %C.decl
  213. // CHECK:STDOUT: .J = %J.decl
  214. // CHECK:STDOUT: .Incomplete = %Incomplete.decl
  215. // CHECK:STDOUT: }
  216. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  217. // CHECK:STDOUT: %J.decl: type = interface_decl @J [concrete = constants.%J.type] {} {}
  218. // CHECK:STDOUT: %Incomplete.decl: type = interface_decl @Incomplete [concrete = constants.%Incomplete.type] {} {}
  219. // CHECK:STDOUT: impl_decl @C.as.J.impl [concrete] {} {
  220. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  221. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [concrete = constants.%J.type]
  222. // CHECK:STDOUT: %.Self: %J.type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  223. // CHECK:STDOUT: %.Self.ref.loc15_19: %J.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  224. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, file.%Incomplete.decl [concrete = constants.%Incomplete.type]
  225. // CHECK:STDOUT: %.Self.as_type.loc15_19: type = facet_access_type %.Self.ref.loc15_19 [symbolic_self = constants.%.Self.binding.as_type]
  226. // CHECK:STDOUT: %.loc15_19: type = converted %.Self.ref.loc15_19, %.Self.as_type.loc15_19 [symbolic_self = constants.%.Self.binding.as_type]
  227. // CHECK:STDOUT: %.Self.ref.loc15_46: %J.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  228. // CHECK:STDOUT: %T.ref: %J.assoc_type = name_ref T, @T.%assoc0 [concrete = constants.%assoc0]
  229. // CHECK:STDOUT: %.Self.as_type.loc15_46: type = facet_access_type %.Self.ref.loc15_46 [symbolic_self = constants.%.Self.binding.as_type]
  230. // CHECK:STDOUT: %.loc15_46: type = converted %.Self.ref.loc15_46, %.Self.as_type.loc15_46 [symbolic_self = constants.%.Self.binding.as_type]
  231. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access constants.%J.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  232. // CHECK:STDOUT: %.loc15_52.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  233. // CHECK:STDOUT: %.loc15_52.2: type = converted %.loc15_52.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  234. // CHECK:STDOUT: %.loc15_13: type = where_expr %.Self [concrete = constants.%J_where.type] {
  235. // CHECK:STDOUT: requirement_base_facet_type constants.%J.type
  236. // CHECK:STDOUT: requirement_impls %.loc15_19, %Incomplete.ref
  237. // CHECK:STDOUT: requirement_rewrite %impl.elem0, %.loc15_52.2
  238. // CHECK:STDOUT: }
  239. // CHECK:STDOUT: }
  240. // CHECK:STDOUT: }
  241. // CHECK:STDOUT:
  242. // CHECK:STDOUT: interface @J {
  243. // CHECK:STDOUT: %Self: %J.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  244. // CHECK:STDOUT: %T: type = assoc_const_decl @T [concrete] {
  245. // CHECK:STDOUT: %assoc0: %J.assoc_type = assoc_entity element0, @J.%T [concrete = constants.%assoc0]
  246. // CHECK:STDOUT: }
  247. // CHECK:STDOUT:
  248. // CHECK:STDOUT: !members:
  249. // CHECK:STDOUT: .Self = %Self
  250. // CHECK:STDOUT: .T = @T.%assoc0
  251. // CHECK:STDOUT: witness = (%T)
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: !requires:
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: interface @Incomplete;
  257. // CHECK:STDOUT:
  258. // CHECK:STDOUT: generic assoc_const @T(@J.%Self: %J.type) {
  259. // CHECK:STDOUT: assoc_const T:! type;
  260. // CHECK:STDOUT: }
  261. // CHECK:STDOUT:
  262. // CHECK:STDOUT: impl @C.as.J.impl: %C.ref as %.loc15_13;
  263. // CHECK:STDOUT:
  264. // CHECK:STDOUT: class @C {
  265. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  266. // CHECK:STDOUT: complete_type_witness = %complete_type
  267. // CHECK:STDOUT:
  268. // CHECK:STDOUT: !members:
  269. // CHECK:STDOUT: .Self = constants.%C
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT:
  272. // CHECK:STDOUT: specific @T(constants.%Self) {}
  273. // CHECK:STDOUT:
  274. // CHECK:STDOUT: specific @T(constants.%.Self) {}
  275. // CHECK:STDOUT: