no_definition_in_impl_file.carbon 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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/class/no_definition_in_impl_file.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/no_definition_in_impl_file.carbon
  14. // --- decl_in_api_definition_in_impl.carbon
  15. library "[[@TEST_NAME]]";
  16. class A;
  17. // --- decl_in_api_definition_in_impl.impl.carbon
  18. impl library "[[@TEST_NAME]]";
  19. class A;
  20. class A {}
  21. // --- use_decl_in_api.carbon
  22. library "[[@TEST_NAME]]";
  23. // --- use_decl_in_api.impl.carbon
  24. impl library "[[@TEST_NAME]]";
  25. import library "decl_in_api_definition_in_impl";
  26. // --- decl_only_in_api.carbon
  27. library "[[@TEST_NAME]]";
  28. class B;
  29. // --- decl_only_in_api.impl.carbon
  30. impl library "[[@TEST_NAME]]";
  31. // --- decl_in_api_decl_in_impl.carbon
  32. library "[[@TEST_NAME]]";
  33. class C;
  34. // --- fail_decl_in_api_decl_in_impl.impl.carbon
  35. impl library "[[@TEST_NAME]]";
  36. // CHECK:STDERR: fail_decl_in_api_decl_in_impl.impl.carbon:[[@LINE+4]]:1: error: no definition found for declaration in impl file [MissingDefinitionInImpl]
  37. // CHECK:STDERR: class C;
  38. // CHECK:STDERR: ^~~~~~~~
  39. // CHECK:STDERR:
  40. class C;
  41. // --- decl_only_in_impl.carbon
  42. library "[[@TEST_NAME]]";
  43. // --- fail_decl_only_in_impl.impl.carbon
  44. impl library "[[@TEST_NAME]]";
  45. // CHECK:STDERR: fail_decl_only_in_impl.impl.carbon:[[@LINE+4]]:1: error: no definition found for declaration in impl file [MissingDefinitionInImpl]
  46. // CHECK:STDERR: class D;
  47. // CHECK:STDERR: ^~~~~~~~
  48. // CHECK:STDERR:
  49. class D;
  50. // CHECK:STDOUT: --- decl_in_api_definition_in_impl.carbon
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: constants {
  53. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  58. // CHECK:STDOUT: .A = %A.decl
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %A.decl: type = class_decl @A [concrete = constants.%A] {} {}
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: class @A;
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: --- decl_in_api_definition_in_impl.impl.carbon
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: constants {
  68. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  69. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  70. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: imports {
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: file {
  77. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  78. // CHECK:STDOUT: .A = %A.decl.loc4
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %default.import.loc2_46.1 = import <none>
  81. // CHECK:STDOUT: %default.import.loc2_46.2 = import <none>
  82. // CHECK:STDOUT: %A.decl.loc4: type = class_decl @A [concrete = constants.%A] {} {}
  83. // CHECK:STDOUT: %A.decl.loc6: type = class_decl @A [concrete = constants.%A] {} {}
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: class @A {
  87. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  88. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  89. // CHECK:STDOUT: complete_type_witness = %complete_type
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !members:
  92. // CHECK:STDOUT: .Self = constants.%A
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: --- use_decl_in_api.carbon
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: file {
  98. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {}
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: --- use_decl_in_api.impl.carbon
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: imports {
  104. // CHECK:STDOUT: %Main.A = import_ref Main//decl_in_api_definition_in_impl, A, unloaded
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: file {
  108. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  109. // CHECK:STDOUT: .A = imports.%Main.A
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %default.import.loc2_31.1 = import <none>
  112. // CHECK:STDOUT: %default.import.loc2_31.2 = import <none>
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: --- decl_only_in_api.carbon
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: constants {
  118. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: file {
  122. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  123. // CHECK:STDOUT: .B = %B.decl
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: %B.decl: type = class_decl @B [concrete = constants.%B] {} {}
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: class @B;
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: --- decl_only_in_api.impl.carbon
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: imports {
  133. // CHECK:STDOUT: %Main.B = import_ref Main//decl_only_in_api, B, unloaded
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: file {
  137. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  138. // CHECK:STDOUT: .B = imports.%Main.B
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT: %default.import.loc2_32.1 = import <none>
  141. // CHECK:STDOUT: %default.import.loc2_32.2 = import <none>
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: --- decl_in_api_decl_in_impl.carbon
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: constants {
  147. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: file {
  151. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  152. // CHECK:STDOUT: .C = %C.decl
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: class @C;
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: --- fail_decl_in_api_decl_in_impl.impl.carbon
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: constants {
  162. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: imports {
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: file {
  169. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  170. // CHECK:STDOUT: .C = %C.decl
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT: %default.import.loc2_40.1 = import <none>
  173. // CHECK:STDOUT: %default.import.loc2_40.2 = import <none>
  174. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: class @C;
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: --- decl_only_in_impl.carbon
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: file {
  182. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {}
  183. // CHECK:STDOUT: }
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: --- fail_decl_only_in_impl.impl.carbon
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: constants {
  188. // CHECK:STDOUT: %D: type = class_type @D [concrete]
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: file {
  192. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  193. // CHECK:STDOUT: .D = %D.decl
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT: %default.import.loc2_33.1 = import <none>
  196. // CHECK:STDOUT: %default.import.loc2_33.2 = import <none>
  197. // CHECK:STDOUT: %D.decl: type = class_decl @D [concrete = constants.%D] {} {}
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: class @D;
  201. // CHECK:STDOUT: