cross_package_import.carbon 23 KB

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