incomplete.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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/interface/incomplete.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/incomplete.carbon
  14. // --- fail_incomplete_type.carbon
  15. library "[[@TEST_NAME]]";
  16. class C;
  17. interface I {
  18. // CHECK:STDERR: fail_incomplete_type.carbon:[[@LINE+7]]:11: error: associated constant has incomplete type `C` [IncompleteTypeInAssociatedConstantDecl]
  19. // CHECK:STDERR: let T:! C;
  20. // CHECK:STDERR: ^
  21. // CHECK:STDERR: fail_incomplete_type.carbon:[[@LINE-6]]:1: note: class was forward declared here [ClassForwardDeclaredHere]
  22. // CHECK:STDERR: class C;
  23. // CHECK:STDERR: ^~~~~~~~
  24. // CHECK:STDERR:
  25. let T:! C;
  26. }
  27. // --- fail_incomplete_extend_constraint.carbon
  28. library "[[@TEST_NAME]]";
  29. constraint A;
  30. interface B {
  31. // CHECK:STDERR: fail_incomplete_extend_constraint.carbon:[[@LINE+7]]:24: error: facet type `A` cannot be identified in `require` declaration [RequireImplsUnidentifiedFacetType]
  32. // CHECK:STDERR: extend require impls A;
  33. // CHECK:STDERR: ^
  34. // CHECK:STDERR: fail_incomplete_extend_constraint.carbon:[[@LINE-6]]:1: note: constraint was forward declared here [NamedConstraintForwardDeclaredHere]
  35. // CHECK:STDERR: constraint A;
  36. // CHECK:STDERR: ^~~~~~~~~~~~~
  37. // CHECK:STDERR:
  38. extend require impls A;
  39. }
  40. // --- fail_extend_require_enclosing.carbon
  41. library "[[@TEST_NAME]]";
  42. interface A {
  43. // CHECK:STDERR: fail_extend_require_enclosing.carbon:[[@LINE+7]]:24: error: `extend require` of incomplete facet type `A` [RequireImplsIncompleteFacetType]
  44. // CHECK:STDERR: extend require impls A;
  45. // CHECK:STDERR: ^
  46. // CHECK:STDERR: fail_extend_require_enclosing.carbon:[[@LINE-4]]:1: note: interface is currently being defined [InterfaceIncompleteWithinDefinition]
  47. // CHECK:STDERR: interface A {
  48. // CHECK:STDERR: ^~~~~~~~~~~~~
  49. // CHECK:STDERR:
  50. extend require impls A;
  51. }
  52. // --- fail_extend_require_enclosing_generic.carbon
  53. library "[[@TEST_NAME]]";
  54. interface A(T:! type) {
  55. // CHECK:STDERR: fail_extend_require_enclosing_generic.carbon:[[@LINE+7]]:24: error: `extend require` of incomplete facet type `A({})` [RequireImplsIncompleteFacetType]
  56. // CHECK:STDERR: extend require impls A({});
  57. // CHECK:STDERR: ^~~~~
  58. // CHECK:STDERR: fail_extend_require_enclosing_generic.carbon:[[@LINE-4]]:1: note: interface is currently being defined [InterfaceIncompleteWithinDefinition]
  59. // CHECK:STDERR: interface A(T:! type) {
  60. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
  61. // CHECK:STDERR:
  62. extend require impls A({});
  63. }
  64. // CHECK:STDOUT: --- fail_incomplete_type.carbon
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: constants {
  67. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  68. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  69. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic]
  70. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  71. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%T [concrete]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: file {
  75. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  76. // CHECK:STDOUT: .C = %C.decl
  77. // CHECK:STDOUT: .I = %I.decl
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  80. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: interface @I {
  84. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  85. // CHECK:STDOUT: %T: <error> = assoc_const_decl @T [concrete] {
  86. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%T [concrete = constants.%assoc0]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: !members:
  90. // CHECK:STDOUT: .Self = %Self
  91. // CHECK:STDOUT: .C = <poisoned>
  92. // CHECK:STDOUT: .T = @T.%assoc0
  93. // CHECK:STDOUT: witness = (%T)
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: !requires:
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: generic assoc_const @T(@I.%Self: %I.type) {
  99. // CHECK:STDOUT: assoc_const T:! <error>;
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: class @C;
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: specific @T(constants.%Self) {}
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: --- fail_incomplete_extend_constraint.carbon
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: constants {
  109. // CHECK:STDOUT: %A.type: type = facet_type <@A> [concrete]
  110. // CHECK:STDOUT: %B.type: type = facet_type <@B> [concrete]
  111. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: file {
  115. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  116. // CHECK:STDOUT: .A = %A.decl
  117. // CHECK:STDOUT: .B = %B.decl
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %A.decl: type = constraint_decl @A [concrete = constants.%A.type] {} {}
  120. // CHECK:STDOUT: %B.decl: type = interface_decl @B [concrete = constants.%B.type] {} {}
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: interface @B {
  124. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: !members:
  127. // CHECK:STDOUT: .Self = %Self
  128. // CHECK:STDOUT: .A = <poisoned>
  129. // CHECK:STDOUT: has_error
  130. // CHECK:STDOUT: witness = ()
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: !requires:
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: constraint @A;
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: --- fail_extend_require_enclosing.carbon
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: constants {
  140. // CHECK:STDOUT: %A.type: type = facet_type <@A> [concrete]
  141. // CHECK:STDOUT: %Self: %A.type = symbolic_binding Self, 0 [symbolic]
  142. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic]
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: file {
  146. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  147. // CHECK:STDOUT: .A = %A.decl
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: %A.decl: type = interface_decl @A [concrete = constants.%A.type] {} {}
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: interface @A {
  153. // CHECK:STDOUT: %Self: %A.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  154. // CHECK:STDOUT: %A.Self.binding.as_type.impls.A.type.require.decl = require_decl @A.Self.binding.as_type.impls.A.type.require [concrete] {
  155. // CHECK:STDOUT: require %Self.as_type impls %A.ref
  156. // CHECK:STDOUT: } {
  157. // CHECK:STDOUT: %Self.as_type: type = facet_access_type @A.%Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  158. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A.type]
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: !members:
  162. // CHECK:STDOUT: .Self = %Self
  163. // CHECK:STDOUT: .A = <poisoned>
  164. // CHECK:STDOUT: witness = ()
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: !requires:
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: generic require @A.Self.binding.as_type.impls.A.type.require(@A.%Self: %A.type) {
  170. // CHECK:STDOUT: %Self: %A.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self)]
  171. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: specific @A.Self.binding.as_type.impls.A.type.require(constants.%Self) {
  175. // CHECK:STDOUT: %Self => constants.%Self
  176. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: --- fail_extend_require_enclosing_generic.carbon
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: constants {
  182. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  183. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
  184. // CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic]
  185. // CHECK:STDOUT: %pattern_type: type = pattern_type type [concrete]
  186. // CHECK:STDOUT: %A.type.464: type = generic_interface_type @A [concrete]
  187. // CHECK:STDOUT: %A.generic: %A.type.464 = struct_value () [concrete]
  188. // CHECK:STDOUT: %A.type.ade: type = facet_type <@A, @A(%T)> [symbolic]
  189. // CHECK:STDOUT: %Self: %A.type.ade = symbolic_binding Self, 1 [symbolic]
  190. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 1, %Self [symbolic]
  191. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  192. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  193. // CHECK:STDOUT: %A.type.69e: type = facet_type <@A, @A(%empty_struct_type)> [concrete]
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: file {
  197. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  198. // CHECK:STDOUT: .A = %A.decl
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT: %A.decl: %A.type.464 = interface_decl @A [concrete = constants.%A.generic] {
  201. // CHECK:STDOUT: %T.patt: %pattern_type = symbolic_binding_pattern T, 0 [concrete]
  202. // CHECK:STDOUT: } {
  203. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  204. // CHECK:STDOUT: %T.loc3_13.2: type = symbolic_binding T, 0 [symbolic = %T.loc3_13.1 (constants.%T)]
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: generic interface @A(%T.loc3_13.2: type) {
  209. // CHECK:STDOUT: %T.loc3_13.1: type = symbolic_binding T, 0 [symbolic = %T.loc3_13.1 (constants.%T)]
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: !definition:
  212. // CHECK:STDOUT: %A.type: type = facet_type <@A, @A(%T.loc3_13.1)> [symbolic = %A.type (constants.%A.type.ade)]
  213. // CHECK:STDOUT: %Self.loc3_23.2: @A.%A.type (%A.type.ade) = symbolic_binding Self, 1 [symbolic = %Self.loc3_23.2 (constants.%Self)]
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: interface {
  216. // CHECK:STDOUT: %Self.loc3_23.1: @A.%A.type (%A.type.ade) = symbolic_binding Self, 1 [symbolic = %Self.loc3_23.2 (constants.%Self)]
  217. // CHECK:STDOUT: %A.Self.binding.as_type.impls.A.type.require.decl = require_decl @A.Self.binding.as_type.impls.A.type.require [concrete] {
  218. // CHECK:STDOUT: require %Self.as_type impls %A.type.loc11_28
  219. // CHECK:STDOUT: } {
  220. // CHECK:STDOUT: %Self.as_type: type = facet_access_type @A.%Self.loc3_23.1 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  221. // CHECK:STDOUT: %A.ref: %A.type.464 = name_ref A, file.%A.decl [concrete = constants.%A.generic]
  222. // CHECK:STDOUT: %.loc11_27: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  223. // CHECK:STDOUT: %.loc11_28: type = converted %.loc11_27, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  224. // CHECK:STDOUT: %A.type.loc11_28: type = facet_type <@A, @A(constants.%empty_struct_type)> [concrete = constants.%A.type.69e]
  225. // CHECK:STDOUT: }
  226. // CHECK:STDOUT:
  227. // CHECK:STDOUT: !members:
  228. // CHECK:STDOUT: .Self = %Self.loc3_23.1
  229. // CHECK:STDOUT: .A = <poisoned>
  230. // CHECK:STDOUT: witness = ()
  231. // CHECK:STDOUT:
  232. // CHECK:STDOUT: !requires:
  233. // CHECK:STDOUT: }
  234. // CHECK:STDOUT: }
  235. // CHECK:STDOUT:
  236. // CHECK:STDOUT: generic require @A.Self.binding.as_type.impls.A.type.require(@A.%T.loc3_13.2: type, @A.%Self.loc3_23.1: @A.%A.type (%A.type.ade)) {
  237. // CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic = %T (constants.%T)]
  238. // CHECK:STDOUT: %A.type.loc11_18: type = facet_type <@A, @A(%T)> [symbolic = %A.type.loc11_18 (constants.%A.type.ade)]
  239. // CHECK:STDOUT: %Self: @A.Self.binding.as_type.impls.A.type.require.%A.type.loc11_18 (%A.type.ade) = symbolic_binding Self, 1 [symbolic = %Self (constants.%Self)]
  240. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 1, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  241. // CHECK:STDOUT: }
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: specific @A(constants.%T) {
  244. // CHECK:STDOUT: %T.loc3_13.1 => constants.%T
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: specific @A(constants.%empty_struct_type) {
  248. // CHECK:STDOUT: %T.loc3_13.1 => constants.%empty_struct_type
  249. // CHECK:STDOUT: }
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: specific @A.Self.binding.as_type.impls.A.type.require(constants.%T, constants.%Self) {
  252. // CHECK:STDOUT: %T => constants.%T
  253. // CHECK:STDOUT: %A.type.loc11_18 => constants.%A.type.ade
  254. // CHECK:STDOUT: %Self => constants.%Self
  255. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT: