implicit_import.carbon 6.5 KB

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