incomplete.carbon 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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_constraint.carbon
  28. library "[[@TEST_NAME]]";
  29. constraint A;
  30. interface B {
  31. // CHECK:STDERR: fail_incomplete_constraint.carbon:[[@LINE+7]]:17: error: facet type `A` cannot be identified in `require` declaration [RequireImplsUnidentifiedFacetType]
  32. // CHECK:STDERR: require impls A;
  33. // CHECK:STDERR: ^
  34. // CHECK:STDERR: fail_incomplete_constraint.carbon:[[@LINE-6]]:1: note: constraint was forward declared here [NamedConstraintForwardDeclaredHere]
  35. // CHECK:STDERR: constraint A;
  36. // CHECK:STDERR: ^~~~~~~~~~~~~
  37. // CHECK:STDERR:
  38. require impls A;
  39. }
  40. // --- incomplete_interface.carbon
  41. library "[[@TEST_NAME]]";
  42. interface A;
  43. interface B {
  44. require impls A;
  45. }
  46. // --- fail_incomplete_interface_in_where.carbon
  47. library "[[@TEST_NAME]]";
  48. interface A;
  49. interface B {
  50. // CHECK:STDERR: fail_incomplete_interface_in_where.carbon:[[@LINE+7]]:25: error: member access into object of incomplete type `A` [IncompleteTypeInMemberAccess]
  51. // CHECK:STDERR: require impls A where .X = {};
  52. // CHECK:STDERR: ^~
  53. // CHECK:STDERR: fail_incomplete_interface_in_where.carbon:[[@LINE-6]]:1: note: interface was forward declared here [InterfaceForwardDeclaredHere]
  54. // CHECK:STDERR: interface A;
  55. // CHECK:STDERR: ^~~~~~~~~~~~
  56. // CHECK:STDERR:
  57. require impls A where .X = {};
  58. }
  59. // CHECK:STDOUT: --- fail_incomplete_type.carbon
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: constants {
  62. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  63. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  64. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic]
  65. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  66. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%T [concrete]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: file {
  70. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  71. // CHECK:STDOUT: .C = %C.decl
  72. // CHECK:STDOUT: .I = %I.decl
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  75. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: interface @I {
  79. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  80. // CHECK:STDOUT: %T: <error> = assoc_const_decl @T [concrete] {
  81. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%T [concrete = constants.%assoc0]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !members:
  85. // CHECK:STDOUT: .Self = %Self
  86. // CHECK:STDOUT: .C = <poisoned>
  87. // CHECK:STDOUT: .T = @T.%assoc0
  88. // CHECK:STDOUT: witness = (%T)
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: !requires:
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: generic assoc_const @T(@I.%Self: %I.type) {
  94. // CHECK:STDOUT: assoc_const T:! <error>;
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: class @C;
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: specific @T(constants.%Self) {}
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: --- fail_incomplete_constraint.carbon
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: constants {
  104. // CHECK:STDOUT: %A.type: type = facet_type <@A> [concrete]
  105. // CHECK:STDOUT: %B.type: type = facet_type <@B> [concrete]
  106. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: file {
  110. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  111. // CHECK:STDOUT: .A = %A.decl
  112. // CHECK:STDOUT: .B = %B.decl
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %A.decl: type = constraint_decl @A [concrete = constants.%A.type] {} {}
  115. // CHECK:STDOUT: %B.decl: type = interface_decl @B [concrete = constants.%B.type] {} {}
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: interface @B {
  119. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: !members:
  122. // CHECK:STDOUT: .Self = %Self
  123. // CHECK:STDOUT: .A = <poisoned>
  124. // CHECK:STDOUT: witness = ()
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: !requires:
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: constraint @A;
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: --- incomplete_interface.carbon
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: constants {
  134. // CHECK:STDOUT: %A.type: type = facet_type <@A> [concrete]
  135. // CHECK:STDOUT: %B.type: type = facet_type <@B> [concrete]
  136. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic]
  137. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic]
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: file {
  141. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  142. // CHECK:STDOUT: .A = %A.decl
  143. // CHECK:STDOUT: .B = %B.decl
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT: %A.decl: type = interface_decl @A [concrete = constants.%A.type] {} {}
  146. // CHECK:STDOUT: %B.decl: type = interface_decl @B [concrete = constants.%B.type] {} {}
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: interface @A;
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: interface @B {
  152. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  153. // CHECK:STDOUT: %B.require0.decl = require_decl @B.require0 [concrete] {
  154. // CHECK:STDOUT: require %Self.as_type impls <@A>
  155. // CHECK:STDOUT: } {
  156. // CHECK:STDOUT: %Self.as_type: type = facet_access_type @B.%Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  157. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A.type]
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: !members:
  161. // CHECK:STDOUT: .Self = %Self
  162. // CHECK:STDOUT: .A = <poisoned>
  163. // CHECK:STDOUT: witness = ()
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: !requires:
  166. // CHECK:STDOUT: @B.require0 {
  167. // CHECK:STDOUT: require @B.require0.%Self.as_type impls <@A>
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: generic require @B.require0(@B.%Self: %B.type) {
  172. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self)]
  173. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: specific @B.require0(constants.%Self) {
  177. // CHECK:STDOUT: %Self => constants.%Self
  178. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: --- fail_incomplete_interface_in_where.carbon
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: constants {
  184. // CHECK:STDOUT: %A.type: type = facet_type <@A> [concrete]
  185. // CHECK:STDOUT: %B.type: type = facet_type <@B> [concrete]
  186. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic]
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: file {
  190. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  191. // CHECK:STDOUT: .A = %A.decl
  192. // CHECK:STDOUT: .B = %B.decl
  193. // CHECK:STDOUT: }
  194. // CHECK:STDOUT: %A.decl: type = interface_decl @A [concrete = constants.%A.type] {} {}
  195. // CHECK:STDOUT: %B.decl: type = interface_decl @B [concrete = constants.%B.type] {} {}
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: interface @A;
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: interface @B {
  201. // CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: !members:
  204. // CHECK:STDOUT: .Self = %Self
  205. // CHECK:STDOUT: .A = <poisoned>
  206. // CHECK:STDOUT: witness = ()
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: !requires:
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT: