fail_undefined_interface.carbon 14 KB

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