fail_undefined_interface.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: file {
  71. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  72. // CHECK:STDOUT: .I = %I.decl
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  75. // CHECK:STDOUT: impl_decl @empty_struct_type.as.I.impl [concrete] {} {
  76. // CHECK:STDOUT: %.loc12_7.1: %empty_struct_type = struct_literal ()
  77. // CHECK:STDOUT: %.loc12_7.2: type = converted %.loc12_7.1, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  78. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: interface @I;
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: impl @empty_struct_type.as.I.impl: %.loc12_7.2 as %I.ref {
  85. // CHECK:STDOUT: !members:
  86. // CHECK:STDOUT: witness = <error>
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: --- fail_class.carbon
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: constants {
  92. // CHECK:STDOUT: %J.type: type = facet_type <@J> [concrete]
  93. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  94. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  95. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: file {
  99. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  100. // CHECK:STDOUT: .J = %J.decl
  101. // CHECK:STDOUT: .C = %C.decl
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %J.decl: type = interface_decl @J [concrete = constants.%J.type] {} {}
  104. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  105. // CHECK:STDOUT: impl_decl @C.as.J.impl [concrete] {} {
  106. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  107. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [concrete = constants.%J.type]
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: interface @J;
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: impl @C.as.J.impl: %C.ref as %J.ref {
  114. // CHECK:STDOUT: !members:
  115. // CHECK:STDOUT: witness = <error>
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: class @C {
  119. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  120. // CHECK:STDOUT: complete_type_witness = %complete_type
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: !members:
  123. // CHECK:STDOUT: .Self = constants.%C
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: --- fail_incomplete_where.carbon
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: constants {
  129. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  130. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  131. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  132. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  133. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  134. // CHECK:STDOUT: %Incomplete.type: type = facet_type <@Incomplete> [concrete]
  135. // CHECK:STDOUT: %.Self: %I.type = bind_symbolic_name .Self [symbolic_self]
  136. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self [symbolic_self]
  137. // CHECK:STDOUT: %I_where.type: type = facet_type <@I where .Self impls @Incomplete> [concrete]
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: file {
  141. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  142. // CHECK:STDOUT: .C = %C.decl
  143. // CHECK:STDOUT: .I = %I.decl
  144. // CHECK:STDOUT: .Incomplete = %Incomplete.decl
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  147. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  148. // CHECK:STDOUT: %Incomplete.decl: type = interface_decl @Incomplete [concrete = constants.%Incomplete.type] {} {}
  149. // CHECK:STDOUT: impl_decl @C.as.I.impl [concrete] {} {
  150. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  151. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  152. // CHECK:STDOUT: %.Self: %I.type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  153. // CHECK:STDOUT: %.Self.ref: %I.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  154. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, file.%Incomplete.decl [concrete = constants.%Incomplete.type]
  155. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self.ref [symbolic_self = constants.%.Self.as_type]
  156. // CHECK:STDOUT: %.loc15_19: type = converted %.Self.ref, %.Self.as_type [symbolic_self = constants.%.Self.as_type]
  157. // CHECK:STDOUT: %.loc15_13: type = where_expr %.Self [concrete = constants.%I_where.type] {
  158. // CHECK:STDOUT: requirement_base_facet_type constants.%I.type
  159. // CHECK:STDOUT: requirement_impls %.loc15_19, %Incomplete.ref
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: interface @I {
  165. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: !members:
  168. // CHECK:STDOUT: .Self = %Self
  169. // CHECK:STDOUT: witness = ()
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: interface @Incomplete;
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: impl @C.as.I.impl: %C.ref as %.loc15_13 {
  175. // CHECK:STDOUT: !members:
  176. // CHECK:STDOUT: witness = <error>
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: class @C {
  180. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  181. // CHECK:STDOUT: complete_type_witness = %complete_type
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: !members:
  184. // CHECK:STDOUT: .Self = constants.%C
  185. // CHECK:STDOUT: }
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: --- fail_declaration_incomplete_where_rewrite.carbon
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: constants {
  190. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  191. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  192. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  193. // CHECK:STDOUT: %J.type: type = facet_type <@J> [concrete]
  194. // CHECK:STDOUT: %Self: %J.type = bind_symbolic_name Self, 0 [symbolic]
  195. // CHECK:STDOUT: %J.assoc_type: type = assoc_entity_type @J [concrete]
  196. // CHECK:STDOUT: %assoc0: %J.assoc_type = assoc_entity element0, @J.%T [concrete]
  197. // CHECK:STDOUT: %Incomplete.type: type = facet_type <@Incomplete> [concrete]
  198. // CHECK:STDOUT: %.Self: %J.type = bind_symbolic_name .Self [symbolic_self]
  199. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self [symbolic_self]
  200. // CHECK:STDOUT: %J.lookup_impl_witness: <witness> = lookup_impl_witness %.Self, @J [symbolic_self]
  201. // CHECK:STDOUT: %J.facet: %J.type = facet_value %.Self.as_type, (%J.lookup_impl_witness) [symbolic_self]
  202. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access %J.lookup_impl_witness, element0 [symbolic_self]
  203. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  204. // CHECK:STDOUT: %J_where.type: type = facet_type <@J where .Self impls @Incomplete and %impl.elem0 = %empty_tuple.type> [concrete]
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: file {
  208. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  209. // CHECK:STDOUT: .C = %C.decl
  210. // CHECK:STDOUT: .J = %J.decl
  211. // CHECK:STDOUT: .Incomplete = %Incomplete.decl
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  214. // CHECK:STDOUT: %J.decl: type = interface_decl @J [concrete = constants.%J.type] {} {}
  215. // CHECK:STDOUT: %Incomplete.decl: type = interface_decl @Incomplete [concrete = constants.%Incomplete.type] {} {}
  216. // CHECK:STDOUT: impl_decl @C.as.J.impl [concrete] {} {
  217. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  218. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [concrete = constants.%J.type]
  219. // CHECK:STDOUT: %.Self: %J.type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  220. // CHECK:STDOUT: %.Self.ref.loc15_19: %J.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  221. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, file.%Incomplete.decl [concrete = constants.%Incomplete.type]
  222. // CHECK:STDOUT: %.Self.as_type.loc15_19: type = facet_access_type %.Self.ref.loc15_19 [symbolic_self = constants.%.Self.as_type]
  223. // CHECK:STDOUT: %.loc15_19: type = converted %.Self.ref.loc15_19, %.Self.as_type.loc15_19 [symbolic_self = constants.%.Self.as_type]
  224. // CHECK:STDOUT: %.Self.ref.loc15_46: %J.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  225. // CHECK:STDOUT: %T.ref: %J.assoc_type = name_ref T, @T.%assoc0 [concrete = constants.%assoc0]
  226. // CHECK:STDOUT: %.Self.as_type.loc15_46: type = facet_access_type %.Self.ref.loc15_46 [symbolic_self = constants.%.Self.as_type]
  227. // CHECK:STDOUT: %.loc15_46: type = converted %.Self.ref.loc15_46, %.Self.as_type.loc15_46 [symbolic_self = constants.%.Self.as_type]
  228. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access constants.%J.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  229. // CHECK:STDOUT: %.loc15_52.1: %empty_tuple.type = tuple_literal ()
  230. // CHECK:STDOUT: %.loc15_52.2: type = converted %.loc15_52.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  231. // CHECK:STDOUT: %.loc15_13: type = where_expr %.Self [concrete = constants.%J_where.type] {
  232. // CHECK:STDOUT: requirement_base_facet_type constants.%J.type
  233. // CHECK:STDOUT: requirement_impls %.loc15_19, %Incomplete.ref
  234. // CHECK:STDOUT: requirement_rewrite %impl.elem0, %.loc15_52.2
  235. // CHECK:STDOUT: }
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT: }
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: interface @J {
  240. // CHECK:STDOUT: %Self: %J.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  241. // CHECK:STDOUT: %T: type = assoc_const_decl @T [concrete] {
  242. // CHECK:STDOUT: %assoc0: %J.assoc_type = assoc_entity element0, @J.%T [concrete = constants.%assoc0]
  243. // CHECK:STDOUT: }
  244. // CHECK:STDOUT:
  245. // CHECK:STDOUT: !members:
  246. // CHECK:STDOUT: .Self = %Self
  247. // CHECK:STDOUT: .T = @T.%assoc0
  248. // CHECK:STDOUT: witness = (%T)
  249. // CHECK:STDOUT: }
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: interface @Incomplete;
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: generic assoc_const @T(@J.%Self: %J.type) {
  254. // CHECK:STDOUT: assoc_const T:! type;
  255. // CHECK:STDOUT: }
  256. // CHECK:STDOUT:
  257. // CHECK:STDOUT: impl @C.as.J.impl: %C.ref as %.loc15_13;
  258. // CHECK:STDOUT:
  259. // CHECK:STDOUT: class @C {
  260. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  261. // CHECK:STDOUT: complete_type_witness = %complete_type
  262. // CHECK:STDOUT:
  263. // CHECK:STDOUT: !members:
  264. // CHECK:STDOUT: .Self = constants.%C
  265. // CHECK:STDOUT: }
  266. // CHECK:STDOUT:
  267. // CHECK:STDOUT: specific @T(constants.%Self) {}
  268. // CHECK:STDOUT:
  269. // CHECK:STDOUT: specific @T(constants.%J.facet) {}
  270. // CHECK:STDOUT: