implicit_import.carbon 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/function/declaration/no_prelude/implicit_import.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/declaration/no_prelude/implicit_import.carbon
  10. // --- basic.carbon
  11. library "[[@TEST_NAME]]";
  12. fn A();
  13. // --- basic.impl.carbon
  14. impl library "[[@TEST_NAME]]";
  15. fn A() {}
  16. // --- extern_api.carbon
  17. library "[[@TEST_NAME]]";
  18. extern fn A();
  19. // --- fail_extern_api.impl.carbon
  20. impl library "[[@TEST_NAME]]";
  21. // CHECK:STDERR: fail_extern_api.impl.carbon:[[@LINE+12]]:1: error: redeclarations of `fn A` must match use of `extern`
  22. // CHECK:STDERR: fn A();
  23. // CHECK:STDERR: ^~~~~~~
  24. // CHECK:STDERR: fail_extern_api.impl.carbon:[[@LINE-5]]:6: in import
  25. // CHECK:STDERR: extern_api.carbon:4:1: note: previously declared here
  26. // CHECK:STDERR: extern fn A();
  27. // CHECK:STDERR: ^~~~~~~~~~~~~~
  28. // CHECK:STDERR:
  29. // CHECK:STDERR: fail_extern_api.impl.carbon:[[@LINE+4]]:1: error: no definition found for declaration in impl file
  30. // CHECK:STDERR: fn A();
  31. // CHECK:STDERR: ^~~~~~~
  32. // CHECK:STDERR:
  33. fn A();
  34. // --- extern_impl.carbon
  35. library "[[@TEST_NAME]]";
  36. fn A();
  37. // --- fail_extern_impl.impl.carbon
  38. impl library "[[@TEST_NAME]]";
  39. // CHECK:STDERR: fail_extern_impl.impl.carbon:[[@LINE+7]]:1: error: redeclarations of `fn A` must match use of `extern`
  40. // CHECK:STDERR: extern fn A();
  41. // CHECK:STDERR: ^~~~~~~~~~~~~~
  42. // CHECK:STDERR: fail_extern_impl.impl.carbon:[[@LINE-5]]:6: in import
  43. // CHECK:STDERR: extern_impl.carbon:4:1: note: previously declared here
  44. // CHECK:STDERR: fn A();
  45. // CHECK:STDERR: ^~~~~~~
  46. extern fn A();
  47. // CHECK:STDOUT: --- basic.carbon
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: constants {
  50. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  51. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  52. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  57. // CHECK:STDOUT: .A = %A.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: fn @A();
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: --- basic.impl.carbon
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: constants {
  67. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  68. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  69. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: imports {
  73. // CHECK:STDOUT: %import_ref: %A.type = import_ref Main//basic, inst+1, loaded [template = constants.%A]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: file {
  77. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  78. // CHECK:STDOUT: .A = %A.decl
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  81. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  82. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @A() {
  86. // CHECK:STDOUT: !entry:
  87. // CHECK:STDOUT: return
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: --- extern_api.carbon
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: constants {
  93. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  94. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  95. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: file {
  99. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  100. // CHECK:STDOUT: .A = %A.decl
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: extern fn @A();
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: --- fail_extern_api.impl.carbon
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: constants {
  110. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  111. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  112. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: imports {
  116. // CHECK:STDOUT: %import_ref: %A.type = import_ref Main//extern_api, inst+1, loaded [template = constants.%A]
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: file {
  120. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  121. // CHECK:STDOUT: .A = %A.decl
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  124. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  125. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: extern fn @A();
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: --- extern_impl.carbon
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: constants {
  133. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  134. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  135. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: file {
  139. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  140. // CHECK:STDOUT: .A = %A.decl
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: fn @A();
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: --- fail_extern_impl.impl.carbon
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: constants {
  150. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  151. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  152. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: imports {
  156. // CHECK:STDOUT: %import_ref: %A.type = import_ref Main//extern_impl, inst+1, loaded [template = constants.%A]
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: file {
  160. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  161. // CHECK:STDOUT: .A = %A.decl
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  164. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  165. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: fn @A();
  169. // CHECK:STDOUT: