cross_package_import.carbon 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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/packages/cross_package_import.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/packages/cross_package_import.carbon
  14. // ============================================================================
  15. // Setup files
  16. // ============================================================================
  17. // --- other_fn.carbon
  18. package Other library "[[@TEST_NAME]]";
  19. fn F() {}
  20. // --- other_fn_extern.carbon
  21. package Other library "[[@TEST_NAME]]";
  22. extern fn F();
  23. // --- other_fn_conflict.carbon
  24. package Other library "[[@TEST_NAME]]";
  25. fn F(x: ()) {}
  26. // --- other_fn2.carbon
  27. package Other library "[[@TEST_NAME]]";
  28. fn F2() {}
  29. // --- other_fn_use.carbon
  30. package Other library "[[@TEST_NAME]]";
  31. import library "other_fn";
  32. fn G() { F(); }
  33. // --- main_other_ns.carbon
  34. library "[[@TEST_NAME]]";
  35. namespace Other;
  36. // ============================================================================
  37. // Test files
  38. // ============================================================================
  39. // --- main_use_other.carbon
  40. library "[[@TEST_NAME]]";
  41. import Other library "other_fn";
  42. import Other library "other_fn2";
  43. fn Run() {
  44. Other.F();
  45. Other.F2();
  46. }
  47. // --- fail_todo_main_use_other_extern.carbon
  48. library "[[@TEST_NAME]]";
  49. // CHECK:STDERR: fail_todo_main_use_other_extern.carbon:[[@LINE+8]]:1: in import [InImport]
  50. // CHECK:STDERR: other_fn_extern.carbon:4:1: error: duplicate name `F` being declared in the same scope [NameDeclDuplicate]
  51. // CHECK:STDERR: extern fn F();
  52. // CHECK:STDERR: ^~~~~~~~~~~~~~
  53. // CHECK:STDERR: fail_todo_main_use_other_extern.carbon:[[@LINE+4]]:1: in import [InImport]
  54. // CHECK:STDERR: other_fn.carbon:4:1: note: name is previously declared here [NameDeclPrevious]
  55. // CHECK:STDERR: fn F() {}
  56. // CHECK:STDERR: ^~~~~~~~
  57. import Other library "other_fn";
  58. import Other library "other_fn_extern";
  59. fn Run() {
  60. // CHECK:STDERR: fail_todo_main_use_other_extern.carbon:[[@LINE+4]]:3: note: in name lookup for `F` [InNameLookup]
  61. // CHECK:STDERR: Other.F();
  62. // CHECK:STDERR: ^~~~~~~
  63. // CHECK:STDERR:
  64. Other.F();
  65. }
  66. // --- main_unused_other_ambiguous.carbon
  67. library "[[@TEST_NAME]]";
  68. import Other library "other_fn";
  69. import Other library "other_fn_conflict";
  70. // --- fail_main_use_other_ambiguous.carbon
  71. library "[[@TEST_NAME]]";
  72. // CHECK:STDERR: fail_main_use_other_ambiguous.carbon:[[@LINE+8]]:1: in import [InImport]
  73. // CHECK:STDERR: other_fn_conflict.carbon:4:1: error: duplicate name `F` being declared in the same scope [NameDeclDuplicate]
  74. // CHECK:STDERR: fn F(x: ()) {}
  75. // CHECK:STDERR: ^~~~~~~~~~~~~
  76. // CHECK:STDERR: fail_main_use_other_ambiguous.carbon:[[@LINE+4]]:1: in import [InImport]
  77. // CHECK:STDERR: other_fn.carbon:4:1: note: name is previously declared here [NameDeclPrevious]
  78. // CHECK:STDERR: fn F() {}
  79. // CHECK:STDERR: ^~~~~~~~
  80. import Other library "other_fn";
  81. import Other library "other_fn_conflict";
  82. fn Run() {
  83. // CHECK:STDERR: fail_main_use_other_ambiguous.carbon:[[@LINE+4]]:3: note: in name lookup for `F` [InNameLookup]
  84. // CHECK:STDERR: Other.F();
  85. // CHECK:STDERR: ^~~~~~~
  86. // CHECK:STDERR:
  87. Other.F();
  88. }
  89. // --- fail_main_namespace_conflict.carbon
  90. library "[[@TEST_NAME]]";
  91. import library "main_other_ns";
  92. // CHECK:STDERR: fail_main_namespace_conflict.carbon:[[@LINE+8]]:1: error: duplicate name `Other` being declared in the same scope [NameDeclDuplicate]
  93. // CHECK:STDERR: import Other library "other_fn";
  94. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. // CHECK:STDERR: fail_main_namespace_conflict.carbon:[[@LINE-4]]:1: in import [InImport]
  96. // CHECK:STDERR: main_other_ns.carbon:4:1: note: name is previously declared here [NameDeclPrevious]
  97. // CHECK:STDERR: namespace Other;
  98. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  99. // CHECK:STDERR:
  100. import Other library "other_fn";
  101. // CHECK:STDERR: fail_main_namespace_conflict.carbon:[[@LINE+8]]:1: error: redeclaration of `fn F` is redundant [RedeclRedundant]
  102. // CHECK:STDERR: fn Other.F() {}
  103. // CHECK:STDERR: ^~~~~~~~~~~~~~
  104. // CHECK:STDERR: fail_main_namespace_conflict.carbon:[[@LINE-5]]:1: in import [InImport]
  105. // CHECK:STDERR: other_fn.carbon:4:1: note: previously declared here [RedeclPrevDecl]
  106. // CHECK:STDERR: fn F() {}
  107. // CHECK:STDERR: ^~~~~~~~
  108. // CHECK:STDERR:
  109. fn Other.F() {}
  110. // --- fail_main_reopen_other.carbon
  111. library "[[@TEST_NAME]]";
  112. import Other library "other_fn";
  113. // CHECK:STDERR: fail_main_reopen_other.carbon:[[@LINE+7]]:11: error: duplicate name `Other` being declared in the same scope [NameDeclDuplicate]
  114. // CHECK:STDERR: namespace Other;
  115. // CHECK:STDERR: ^~~~~
  116. // CHECK:STDERR: fail_main_reopen_other.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious]
  117. // CHECK:STDERR: import Other library "other_fn";
  118. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. // CHECK:STDERR:
  120. namespace Other;
  121. // This is not diagnosed after the diagnostic on `namespace Other;`.
  122. fn Other.G() {}
  123. // --- fail_main_reopen_other_nested.carbon
  124. library "[[@TEST_NAME]]";
  125. import Other library "other_fn";
  126. // CHECK:STDERR: fail_main_reopen_other_nested.carbon:[[@LINE+7]]:11: error: imported packages cannot be used for declarations [QualifiedDeclOutsidePackage]
  127. // CHECK:STDERR: namespace Other.Nested;
  128. // CHECK:STDERR: ^~~~~
  129. // CHECK:STDERR: fail_main_reopen_other_nested.carbon:[[@LINE-5]]:1: note: package imported here [QualifiedDeclOutsidePackageSource]
  130. // CHECK:STDERR: import Other library "other_fn";
  131. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  132. // CHECK:STDERR:
  133. namespace Other.Nested;
  134. // This is not diagnosed after the diagnostic on `namespace Other;`.
  135. fn Other.Nested.F() {}
  136. // --- fail_main_add_to_other.carbon
  137. library "[[@TEST_NAME]]";
  138. import Other library "other_fn";
  139. // CHECK:STDERR: fail_main_add_to_other.carbon:[[@LINE+7]]:4: error: imported packages cannot be used for declarations [QualifiedDeclOutsidePackage]
  140. // CHECK:STDERR: fn Other.G() {}
  141. // CHECK:STDERR: ^~~~~
  142. // CHECK:STDERR: fail_main_add_to_other.carbon:[[@LINE-5]]:1: note: package imported here [QualifiedDeclOutsidePackageSource]
  143. // CHECK:STDERR: import Other library "other_fn";
  144. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145. // CHECK:STDERR:
  146. fn Other.G() {}
  147. // --- fail_use_other_fn_use.carbon
  148. library "[[@TEST_NAME]]";
  149. import Other library "other_fn_use";
  150. // CHECK:STDERR: fail_use_other_fn_use.carbon:[[@LINE+4]]:13: error: member name `F` not found in `Other` [MemberNameNotFoundInInstScope]
  151. // CHECK:STDERR: fn UseF() { Other.F(); }
  152. // CHECK:STDERR: ^~~~~~~
  153. // CHECK:STDERR:
  154. fn UseF() { Other.F(); }
  155. // CHECK:STDOUT: --- other_fn.carbon
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: constants {
  158. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  159. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: file {
  163. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  164. // CHECK:STDOUT: .F = %F.decl
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: fn @F() {
  170. // CHECK:STDOUT: !entry:
  171. // CHECK:STDOUT: return
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: --- other_fn_extern.carbon
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: constants {
  177. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  178. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: file {
  182. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  183. // CHECK:STDOUT: .F = %F.decl
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: extern fn @F();
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: --- other_fn_conflict.carbon
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: constants {
  193. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  194. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  195. // CHECK:STDOUT: %pattern_type: type = pattern_type %empty_tuple.type [concrete]
  196. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  197. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: file {
  201. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  202. // CHECK:STDOUT: .F = %F.decl
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  205. // CHECK:STDOUT: %x.patt: %pattern_type = value_binding_pattern x [concrete]
  206. // CHECK:STDOUT: %x.param_patt: %pattern_type = value_param_pattern %x.patt, call_param0 [concrete]
  207. // CHECK:STDOUT: } {
  208. // CHECK:STDOUT: %x.param: %empty_tuple.type = value_param call_param0
  209. // CHECK:STDOUT: %.loc4_10.1: type = splice_block %.loc4_10.3 [concrete = constants.%empty_tuple.type] {
  210. // CHECK:STDOUT: %.loc4_10.2: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  211. // CHECK:STDOUT: %.loc4_10.3: type = converted %.loc4_10.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT: %x: %empty_tuple.type = value_binding x, %x.param
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT: }
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: fn @F(%x.param: %empty_tuple.type) {
  218. // CHECK:STDOUT: !entry:
  219. // CHECK:STDOUT: return
  220. // CHECK:STDOUT: }
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: --- other_fn2.carbon
  223. // CHECK:STDOUT:
  224. // CHECK:STDOUT: constants {
  225. // CHECK:STDOUT: %F2.type: type = fn_type @F2 [concrete]
  226. // CHECK:STDOUT: %F2: %F2.type = struct_value () [concrete]
  227. // CHECK:STDOUT: }
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: file {
  230. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  231. // CHECK:STDOUT: .F2 = %F2.decl
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT: %F2.decl: %F2.type = fn_decl @F2 [concrete = constants.%F2] {} {}
  234. // CHECK:STDOUT: }
  235. // CHECK:STDOUT:
  236. // CHECK:STDOUT: fn @F2() {
  237. // CHECK:STDOUT: !entry:
  238. // CHECK:STDOUT: return
  239. // CHECK:STDOUT: }
  240. // CHECK:STDOUT:
  241. // CHECK:STDOUT: --- other_fn_use.carbon
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: constants {
  244. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  245. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  246. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  247. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  248. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  249. // CHECK:STDOUT: }
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: imports {
  252. // CHECK:STDOUT: %Other.F: %F.type = import_ref Other//other_fn, F, loaded [concrete = constants.%F]
  253. // CHECK:STDOUT: }
  254. // CHECK:STDOUT:
  255. // CHECK:STDOUT: file {
  256. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  257. // CHECK:STDOUT: .F = imports.%Other.F
  258. // CHECK:STDOUT: .G = %G.decl
  259. // CHECK:STDOUT: }
  260. // CHECK:STDOUT: %default.import = import <none>
  261. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  262. // CHECK:STDOUT: }
  263. // CHECK:STDOUT:
  264. // CHECK:STDOUT: fn @G() {
  265. // CHECK:STDOUT: !entry:
  266. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Other.F [concrete = constants.%F]
  267. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  268. // CHECK:STDOUT: return
  269. // CHECK:STDOUT: }
  270. // CHECK:STDOUT:
  271. // CHECK:STDOUT: fn @F [from "other_fn.carbon"];
  272. // CHECK:STDOUT:
  273. // CHECK:STDOUT: --- main_other_ns.carbon
  274. // CHECK:STDOUT:
  275. // CHECK:STDOUT: file {
  276. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  277. // CHECK:STDOUT: .Other = %Other
  278. // CHECK:STDOUT: }
  279. // CHECK:STDOUT: %Other: <namespace> = namespace [concrete] {}
  280. // CHECK:STDOUT: }
  281. // CHECK:STDOUT:
  282. // CHECK:STDOUT: --- main_use_other.carbon
  283. // CHECK:STDOUT:
  284. // CHECK:STDOUT: constants {
  285. // CHECK:STDOUT: %Run.type: type = fn_type @Run [concrete]
  286. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  287. // CHECK:STDOUT: %Run: %Run.type = struct_value () [concrete]
  288. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  289. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  290. // CHECK:STDOUT: %F2.type: type = fn_type @F2 [concrete]
  291. // CHECK:STDOUT: %F2: %F2.type = struct_value () [concrete]
  292. // CHECK:STDOUT: }
  293. // CHECK:STDOUT:
  294. // CHECK:STDOUT: imports {
  295. // CHECK:STDOUT: %Other: <namespace> = namespace file.%Other.import, [concrete] {
  296. // CHECK:STDOUT: .F = %Other.F
  297. // CHECK:STDOUT: .F2 = %Other.F2
  298. // CHECK:STDOUT: import Other//other_fn
  299. // CHECK:STDOUT: import Other//other_fn2
  300. // CHECK:STDOUT: }
  301. // CHECK:STDOUT: %Other.F: %F.type = import_ref Other//other_fn, F, loaded [concrete = constants.%F]
  302. // CHECK:STDOUT: %Other.F2: %F2.type = import_ref Other//other_fn2, F2, loaded [concrete = constants.%F2]
  303. // CHECK:STDOUT: }
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: file {
  306. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  307. // CHECK:STDOUT: .Other = imports.%Other
  308. // CHECK:STDOUT: .Run = %Run.decl
  309. // CHECK:STDOUT: }
  310. // CHECK:STDOUT: %Other.import = import Other
  311. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [concrete = constants.%Run] {} {}
  312. // CHECK:STDOUT: }
  313. // CHECK:STDOUT:
  314. // CHECK:STDOUT: fn @Run() {
  315. // CHECK:STDOUT: !entry:
  316. // CHECK:STDOUT: %Other.ref.loc8: <namespace> = name_ref Other, imports.%Other [concrete = imports.%Other]
  317. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Other.F [concrete = constants.%F]
  318. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  319. // CHECK:STDOUT: %Other.ref.loc9: <namespace> = name_ref Other, imports.%Other [concrete = imports.%Other]
  320. // CHECK:STDOUT: %F2.ref: %F2.type = name_ref F2, imports.%Other.F2 [concrete = constants.%F2]
  321. // CHECK:STDOUT: %F2.call: init %empty_tuple.type = call %F2.ref()
  322. // CHECK:STDOUT: return
  323. // CHECK:STDOUT: }
  324. // CHECK:STDOUT:
  325. // CHECK:STDOUT: fn @F [from "other_fn.carbon"];
  326. // CHECK:STDOUT:
  327. // CHECK:STDOUT: fn @F2 [from "other_fn2.carbon"];
  328. // CHECK:STDOUT:
  329. // CHECK:STDOUT: --- fail_todo_main_use_other_extern.carbon
  330. // CHECK:STDOUT:
  331. // CHECK:STDOUT: constants {
  332. // CHECK:STDOUT: %Run.type: type = fn_type @Run [concrete]
  333. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  334. // CHECK:STDOUT: %Run: %Run.type = struct_value () [concrete]
  335. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  336. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  337. // CHECK:STDOUT: }
  338. // CHECK:STDOUT:
  339. // CHECK:STDOUT: imports {
  340. // CHECK:STDOUT: %Other: <namespace> = namespace file.%Other.import, [concrete] {
  341. // CHECK:STDOUT: .F = %Other.F
  342. // CHECK:STDOUT: import Other//other_fn
  343. // CHECK:STDOUT: import Other//other_fn_extern
  344. // CHECK:STDOUT: }
  345. // CHECK:STDOUT: %Other.F: %F.type = import_ref Other//other_fn, F, loaded [concrete = constants.%F]
  346. // CHECK:STDOUT: }
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: file {
  349. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  350. // CHECK:STDOUT: .Other = imports.%Other
  351. // CHECK:STDOUT: .Run = %Run.decl
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT: %Other.import = import Other
  354. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [concrete = constants.%Run] {} {}
  355. // CHECK:STDOUT: }
  356. // CHECK:STDOUT:
  357. // CHECK:STDOUT: fn @Run() {
  358. // CHECK:STDOUT: !entry:
  359. // CHECK:STDOUT: %Other.ref: <namespace> = name_ref Other, imports.%Other [concrete = imports.%Other]
  360. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Other.F [concrete = constants.%F]
  361. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  362. // CHECK:STDOUT: return
  363. // CHECK:STDOUT: }
  364. // CHECK:STDOUT:
  365. // CHECK:STDOUT: fn @F [from "other_fn.carbon"];
  366. // CHECK:STDOUT:
  367. // CHECK:STDOUT: --- main_unused_other_ambiguous.carbon
  368. // CHECK:STDOUT:
  369. // CHECK:STDOUT: imports {
  370. // CHECK:STDOUT: %Other: <namespace> = namespace file.%Other.import, [concrete] {
  371. // CHECK:STDOUT: import Other//other_fn
  372. // CHECK:STDOUT: import Other//other_fn_conflict
  373. // CHECK:STDOUT: }
  374. // CHECK:STDOUT: }
  375. // CHECK:STDOUT:
  376. // CHECK:STDOUT: file {
  377. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  378. // CHECK:STDOUT: .Other = imports.%Other
  379. // CHECK:STDOUT: }
  380. // CHECK:STDOUT: %Other.import = import Other
  381. // CHECK:STDOUT: }
  382. // CHECK:STDOUT:
  383. // CHECK:STDOUT: --- fail_main_use_other_ambiguous.carbon
  384. // CHECK:STDOUT:
  385. // CHECK:STDOUT: constants {
  386. // CHECK:STDOUT: %Run.type: type = fn_type @Run [concrete]
  387. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  388. // CHECK:STDOUT: %Run: %Run.type = struct_value () [concrete]
  389. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  390. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  391. // CHECK:STDOUT: }
  392. // CHECK:STDOUT:
  393. // CHECK:STDOUT: imports {
  394. // CHECK:STDOUT: %Other: <namespace> = namespace file.%Other.import, [concrete] {
  395. // CHECK:STDOUT: .F = %Other.F
  396. // CHECK:STDOUT: import Other//other_fn
  397. // CHECK:STDOUT: import Other//other_fn_conflict
  398. // CHECK:STDOUT: }
  399. // CHECK:STDOUT: %Other.F: %F.type = import_ref Other//other_fn, F, loaded [concrete = constants.%F]
  400. // CHECK:STDOUT: }
  401. // CHECK:STDOUT:
  402. // CHECK:STDOUT: file {
  403. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  404. // CHECK:STDOUT: .Other = imports.%Other
  405. // CHECK:STDOUT: .Run = %Run.decl
  406. // CHECK:STDOUT: }
  407. // CHECK:STDOUT: %Other.import = import Other
  408. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [concrete = constants.%Run] {} {}
  409. // CHECK:STDOUT: }
  410. // CHECK:STDOUT:
  411. // CHECK:STDOUT: fn @Run() {
  412. // CHECK:STDOUT: !entry:
  413. // CHECK:STDOUT: %Other.ref: <namespace> = name_ref Other, imports.%Other [concrete = imports.%Other]
  414. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Other.F [concrete = constants.%F]
  415. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  416. // CHECK:STDOUT: return
  417. // CHECK:STDOUT: }
  418. // CHECK:STDOUT:
  419. // CHECK:STDOUT: fn @F [from "other_fn.carbon"];
  420. // CHECK:STDOUT:
  421. // CHECK:STDOUT: --- fail_main_namespace_conflict.carbon
  422. // CHECK:STDOUT:
  423. // CHECK:STDOUT: constants {
  424. // CHECK:STDOUT: %F.type.a71006.1: type = fn_type @F.1 [concrete]
  425. // CHECK:STDOUT: %F.680f0e.1: %F.type.a71006.1 = struct_value () [concrete]
  426. // CHECK:STDOUT: %F.type.a71006.2: type = fn_type @F.loc23 [concrete]
  427. // CHECK:STDOUT: %F.680f0e.2: %F.type.a71006.2 = struct_value () [concrete]
  428. // CHECK:STDOUT: }
  429. // CHECK:STDOUT:
  430. // CHECK:STDOUT: imports {
  431. // CHECK:STDOUT: %Main.Other: <namespace> = import_ref Main//main_other_ns, Other, loaded
  432. // CHECK:STDOUT: %Other: <namespace> = namespace %Main.Other, [concrete] {
  433. // CHECK:STDOUT: .F = %Other.F
  434. // CHECK:STDOUT: import Other//other_fn
  435. // CHECK:STDOUT: }
  436. // CHECK:STDOUT: %Other.F: %F.type.a71006.1 = import_ref Other//other_fn, F, loaded [concrete = constants.%F.680f0e.1]
  437. // CHECK:STDOUT: }
  438. // CHECK:STDOUT:
  439. // CHECK:STDOUT: file {
  440. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  441. // CHECK:STDOUT: .Other = imports.%Other
  442. // CHECK:STDOUT: }
  443. // CHECK:STDOUT: %default.import = import <none>
  444. // CHECK:STDOUT: %Other.import = import Other
  445. // CHECK:STDOUT: %F.decl: %F.type.a71006.2 = fn_decl @F.loc23 [concrete = constants.%F.680f0e.2] {} {}
  446. // CHECK:STDOUT: }
  447. // CHECK:STDOUT:
  448. // CHECK:STDOUT: fn @F.1 [from "other_fn.carbon"];
  449. // CHECK:STDOUT:
  450. // CHECK:STDOUT: fn @F.loc23() {
  451. // CHECK:STDOUT: !entry:
  452. // CHECK:STDOUT: return
  453. // CHECK:STDOUT: }
  454. // CHECK:STDOUT:
  455. // CHECK:STDOUT: --- fail_main_reopen_other.carbon
  456. // CHECK:STDOUT:
  457. // CHECK:STDOUT: constants {
  458. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  459. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  460. // CHECK:STDOUT: }
  461. // CHECK:STDOUT:
  462. // CHECK:STDOUT: imports {
  463. // CHECK:STDOUT: %Other: <namespace> = namespace file.%Other.import, [concrete] {
  464. // CHECK:STDOUT: .G = file.%G.decl
  465. // CHECK:STDOUT: import Other//other_fn
  466. // CHECK:STDOUT: }
  467. // CHECK:STDOUT: }
  468. // CHECK:STDOUT:
  469. // CHECK:STDOUT: file {
  470. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  471. // CHECK:STDOUT: .Other = imports.%Other
  472. // CHECK:STDOUT: }
  473. // CHECK:STDOUT: %Other.import = import Other
  474. // CHECK:STDOUT: %Other: <namespace> = namespace [concrete] {
  475. // CHECK:STDOUT: .G = %G.decl
  476. // CHECK:STDOUT: import Other//other_fn
  477. // CHECK:STDOUT: }
  478. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  479. // CHECK:STDOUT: }
  480. // CHECK:STDOUT:
  481. // CHECK:STDOUT: fn @G() {
  482. // CHECK:STDOUT: !entry:
  483. // CHECK:STDOUT: return
  484. // CHECK:STDOUT: }
  485. // CHECK:STDOUT:
  486. // CHECK:STDOUT: --- fail_main_reopen_other_nested.carbon
  487. // CHECK:STDOUT:
  488. // CHECK:STDOUT: constants {
  489. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  490. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  491. // CHECK:STDOUT: }
  492. // CHECK:STDOUT:
  493. // CHECK:STDOUT: imports {
  494. // CHECK:STDOUT: %Other: <namespace> = namespace file.%Other.import, [concrete] {
  495. // CHECK:STDOUT: .Nested = file.%Nested
  496. // CHECK:STDOUT: import Other//other_fn
  497. // CHECK:STDOUT: }
  498. // CHECK:STDOUT: }
  499. // CHECK:STDOUT:
  500. // CHECK:STDOUT: file {
  501. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  502. // CHECK:STDOUT: .Other = imports.%Other
  503. // CHECK:STDOUT: }
  504. // CHECK:STDOUT: %Other.import = import Other
  505. // CHECK:STDOUT: %Nested: <namespace> = namespace [concrete] {
  506. // CHECK:STDOUT: .F = %F.decl
  507. // CHECK:STDOUT: }
  508. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  509. // CHECK:STDOUT: }
  510. // CHECK:STDOUT:
  511. // CHECK:STDOUT: fn @F() {
  512. // CHECK:STDOUT: !entry:
  513. // CHECK:STDOUT: return
  514. // CHECK:STDOUT: }
  515. // CHECK:STDOUT:
  516. // CHECK:STDOUT: --- fail_main_add_to_other.carbon
  517. // CHECK:STDOUT:
  518. // CHECK:STDOUT: constants {
  519. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  520. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  521. // CHECK:STDOUT: }
  522. // CHECK:STDOUT:
  523. // CHECK:STDOUT: imports {
  524. // CHECK:STDOUT: %Other: <namespace> = namespace file.%Other.import, [concrete] {
  525. // CHECK:STDOUT: .G = file.%G.decl
  526. // CHECK:STDOUT: import Other//other_fn
  527. // CHECK:STDOUT: }
  528. // CHECK:STDOUT: }
  529. // CHECK:STDOUT:
  530. // CHECK:STDOUT: file {
  531. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  532. // CHECK:STDOUT: .Other = imports.%Other
  533. // CHECK:STDOUT: }
  534. // CHECK:STDOUT: %Other.import = import Other
  535. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  536. // CHECK:STDOUT: }
  537. // CHECK:STDOUT:
  538. // CHECK:STDOUT: fn @G() {
  539. // CHECK:STDOUT: !entry:
  540. // CHECK:STDOUT: return
  541. // CHECK:STDOUT: }
  542. // CHECK:STDOUT:
  543. // CHECK:STDOUT: --- fail_use_other_fn_use.carbon
  544. // CHECK:STDOUT:
  545. // CHECK:STDOUT: constants {
  546. // CHECK:STDOUT: %UseF.type: type = fn_type @UseF [concrete]
  547. // CHECK:STDOUT: %UseF: %UseF.type = struct_value () [concrete]
  548. // CHECK:STDOUT: }
  549. // CHECK:STDOUT:
  550. // CHECK:STDOUT: imports {
  551. // CHECK:STDOUT: %Other: <namespace> = namespace file.%Other.import, [concrete] {
  552. // CHECK:STDOUT: .F = <poisoned>
  553. // CHECK:STDOUT: import Other//other_fn_use
  554. // CHECK:STDOUT: }
  555. // CHECK:STDOUT: }
  556. // CHECK:STDOUT:
  557. // CHECK:STDOUT: file {
  558. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  559. // CHECK:STDOUT: .Other = imports.%Other
  560. // CHECK:STDOUT: .UseF = %UseF.decl
  561. // CHECK:STDOUT: }
  562. // CHECK:STDOUT: %Other.import = import Other
  563. // CHECK:STDOUT: %UseF.decl: %UseF.type = fn_decl @UseF [concrete = constants.%UseF] {} {}
  564. // CHECK:STDOUT: }
  565. // CHECK:STDOUT:
  566. // CHECK:STDOUT: fn @UseF() {
  567. // CHECK:STDOUT: !entry:
  568. // CHECK:STDOUT: %Other.ref: <namespace> = name_ref Other, imports.%Other [concrete = imports.%Other]
  569. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [concrete = <error>]
  570. // CHECK:STDOUT: return
  571. // CHECK:STDOUT: }
  572. // CHECK:STDOUT: