import.carbon 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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/class/generic/import.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/import.carbon
  10. // --- foo.carbon
  11. library "foo";
  12. class Class(T:! type);
  13. class CompleteClass(T:! type) {
  14. var n: i32;
  15. fn F() -> i32 { return 0; }
  16. }
  17. fn F() -> CompleteClass(i32);
  18. // --- foo.impl.carbon
  19. impl library "foo";
  20. class Class(T:! type) {
  21. var x: T;
  22. }
  23. fn F() -> CompleteClass(i32) {
  24. return {.n = 1};
  25. }
  26. // --- use_foo.carbon
  27. library "use_foo";
  28. import library "foo";
  29. fn Use() -> i32 {
  30. var v: CompleteClass(i32) = F();
  31. return v.F();
  32. }
  33. // --- fail_todo_use_foo.carbon
  34. library "fail_todo_use_foo";
  35. import library "foo";
  36. fn Use() -> i32 {
  37. var v: CompleteClass(i32) = F();
  38. // TODO: This should be accepted.
  39. // CHECK:STDERR: fail_todo_use_foo.carbon:[[@LINE+4]]:10: ERROR: Cannot implicitly convert from `CompleteClass` to `CompleteClass`.
  40. // CHECK:STDERR: return v.n;
  41. // CHECK:STDERR: ^~~
  42. // CHECK:STDERR:
  43. return v.n;
  44. }
  45. // --- fail_generic_arg_mismatch.carbon
  46. library "fail_generic_arg_mismatch";
  47. import library "foo";
  48. fn Use() {
  49. // TODO: Include the generic arguments in the formatted type name.
  50. // CHECK:STDERR: fail_generic_arg_mismatch.carbon:[[@LINE+4]]:3: ERROR: Cannot implicitly convert from `CompleteClass` to `CompleteClass`.
  51. // CHECK:STDERR: var v: CompleteClass(i32*) = F();
  52. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. // CHECK:STDERR:
  54. var v: CompleteClass(i32*) = F();
  55. }
  56. // --- fail_bad_foo.impl.carbon
  57. impl library "foo";
  58. // CHECK:STDERR: fail_bad_foo.impl.carbon:[[@LINE+5]]:13: ERROR: Redeclaration differs at parameter 1.
  59. // CHECK:STDERR: class Class(U:! type) {
  60. // CHECK:STDERR: ^
  61. // CHECK:STDERR: fail_bad_foo.impl.carbon: Previous declaration's corresponding parameter here.
  62. // CHECK:STDERR:
  63. class Class(U:! type) {
  64. // CHECK:STDERR: fail_bad_foo.impl.carbon:[[@LINE+3]]:10: ERROR: Name `T` not found.
  65. // CHECK:STDERR: var x: T;
  66. // CHECK:STDERR: ^
  67. var x: T;
  68. }
  69. // CHECK:STDOUT: --- foo.carbon
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: constants {
  72. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  73. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  74. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  75. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  76. // CHECK:STDOUT: %Class.2: type = class_type @Class [template]
  77. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  78. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  79. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass [template]
  80. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  81. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  82. // CHECK:STDOUT: %.2: type = unbound_element_type %CompleteClass.2, i32 [template]
  83. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  84. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  85. // CHECK:STDOUT: %.3: type = struct_type {.n: i32} [template]
  86. // CHECK:STDOUT: %.4: i32 = int_literal 0 [template]
  87. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, (i32) [template]
  88. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  89. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: file {
  93. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  94. // CHECK:STDOUT: .Core = %Core
  95. // CHECK:STDOUT: .Class = %Class.decl
  96. // CHECK:STDOUT: .CompleteClass = %CompleteClass.decl
  97. // CHECK:STDOUT: .F = %F.decl
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  100. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  101. // CHECK:STDOUT: %T.loc4_13.1: type = param T
  102. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = constants.%T]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %CompleteClass.decl: %CompleteClass.type = class_decl @CompleteClass [template = constants.%CompleteClass.1] {
  105. // CHECK:STDOUT: %T.loc6_21.1: type = param T
  106. // CHECK:STDOUT: %T.loc6_21.2: type = bind_symbolic_name T 0, %T.loc6_21.1 [symbolic = constants.%T]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  109. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  110. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  111. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {
  112. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, %CompleteClass.decl [template = constants.%CompleteClass.1]
  113. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  114. // CHECK:STDOUT: %.loc11_24.1: type = value_of_initializer %int.make_type_32 [template = i32]
  115. // CHECK:STDOUT: %.loc11_24.2: type = converted %int.make_type_32, %.loc11_24.1 [template = i32]
  116. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, (%.loc11_24.2) [template = constants.%CompleteClass.3]
  117. // CHECK:STDOUT: @F.2.%return: ref %CompleteClass.3 = var <return slot>
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: class @Class;
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: class @CompleteClass {
  124. // CHECK:STDOUT: %int.make_type_32.loc7: init type = call constants.%Int32() [template = i32]
  125. // CHECK:STDOUT: %.loc7_10.1: type = value_of_initializer %int.make_type_32.loc7 [template = i32]
  126. // CHECK:STDOUT: %.loc7_10.2: type = converted %int.make_type_32.loc7, %.loc7_10.1 [template = i32]
  127. // CHECK:STDOUT: %.loc7_8: %.2 = field_decl n, element0 [template]
  128. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {
  129. // CHECK:STDOUT: %int.make_type_32.loc8: init type = call constants.%Int32() [template = i32]
  130. // CHECK:STDOUT: %.loc8_13.1: type = value_of_initializer %int.make_type_32.loc8 [template = i32]
  131. // CHECK:STDOUT: %.loc8_13.2: type = converted %int.make_type_32.loc8, %.loc8_13.1 [template = i32]
  132. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: !members:
  136. // CHECK:STDOUT: .Self = constants.%CompleteClass.2
  137. // CHECK:STDOUT: .n = %.loc7_8
  138. // CHECK:STDOUT: .F = %F.decl
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: fn @F.1() -> i32 {
  144. // CHECK:STDOUT: !entry:
  145. // CHECK:STDOUT: %.loc8: i32 = int_literal 0 [template = constants.%.4]
  146. // CHECK:STDOUT: return %.loc8
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: fn @F.2() -> %CompleteClass.3;
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: --- foo.impl.carbon
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: constants {
  154. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0, <unexpected instref inst+28> [symbolic]
  155. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  156. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  157. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  158. // CHECK:STDOUT: %Class.2: type = class_type @Class [template]
  159. // CHECK:STDOUT: %.2: type = unbound_element_type %Class.2, %T [symbolic]
  160. // CHECK:STDOUT: %.3: type = struct_type {.x: %T} [symbolic]
  161. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  162. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  163. // CHECK:STDOUT: %.4: type = struct_type {.n: i32} [template]
  164. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass [template]
  165. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  166. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  167. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, (i32) [template]
  168. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  169. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  170. // CHECK:STDOUT: %.5: type = ptr_type %.4 [template]
  171. // CHECK:STDOUT: %.6: i32 = int_literal 1 [template]
  172. // CHECK:STDOUT: %struct: %CompleteClass.3 = struct_value (%.6) [template]
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: file {
  176. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  177. // CHECK:STDOUT: .CompleteClass = %import_ref.2
  178. // CHECK:STDOUT: .Core = %Core
  179. // CHECK:STDOUT: .Class = %Class.decl
  180. // CHECK:STDOUT: .F = %F.decl
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT: %import_ref.1: %Class.type = import_ref ir0, inst+5, loaded [template = constants.%Class.1]
  183. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref ir0, inst+12, loaded [template = constants.%CompleteClass.1]
  184. // CHECK:STDOUT: %import_ref.3: %F.type = import_ref ir0, inst+48, loaded [template = constants.%F]
  185. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  186. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  187. // CHECK:STDOUT: %T.loc4_13.1: type = param T
  188. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = constants.%T]
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT: %import_ref.4 = import_ref ir0, inst+15, unloaded
  191. // CHECK:STDOUT: %import_ref.5 = import_ref ir0, inst+25, unloaded
  192. // CHECK:STDOUT: %import_ref.6 = import_ref ir0, inst+33, unloaded
  193. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  194. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  195. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, %import_ref.2 [template = constants.%CompleteClass.1]
  196. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  197. // CHECK:STDOUT: %.loc8_24.1: type = value_of_initializer %int.make_type_32 [template = i32]
  198. // CHECK:STDOUT: %.loc8_24.2: type = converted %int.make_type_32, %.loc8_24.1 [template = i32]
  199. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, (%.loc8_24.2) [template = constants.%CompleteClass.3]
  200. // CHECK:STDOUT: @F.%return: ref %CompleteClass.3 = var <return slot>
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: class @Class {
  205. // CHECK:STDOUT: %T.ref: type = name_ref T, file.%T.loc4_13.2 [symbolic = constants.%T]
  206. // CHECK:STDOUT: %.loc5: %.2 = field_decl x, element0 [template]
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: !members:
  209. // CHECK:STDOUT: .Self = constants.%Class.2
  210. // CHECK:STDOUT: .x = %.loc5
  211. // CHECK:STDOUT: }
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: class @CompleteClass {
  214. // CHECK:STDOUT: !members:
  215. // CHECK:STDOUT: .Self = file.%import_ref.4
  216. // CHECK:STDOUT: .n = file.%import_ref.5
  217. // CHECK:STDOUT: .F = file.%import_ref.6
  218. // CHECK:STDOUT: }
  219. // CHECK:STDOUT:
  220. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: fn @F() -> %return: %CompleteClass.3 {
  223. // CHECK:STDOUT: !entry:
  224. // CHECK:STDOUT: %.loc9_16: i32 = int_literal 1 [template = constants.%.6]
  225. // CHECK:STDOUT: %.loc9_17.1: %.4 = struct_literal (%.loc9_16)
  226. // CHECK:STDOUT: %.loc9_17.2: ref i32 = class_element_access %return, element0
  227. // CHECK:STDOUT: %.loc9_17.3: init i32 = initialize_from %.loc9_16 to %.loc9_17.2 [template = constants.%.6]
  228. // CHECK:STDOUT: %.loc9_17.4: init %CompleteClass.3 = class_init (%.loc9_17.3), %return [template = constants.%struct]
  229. // CHECK:STDOUT: %.loc9_18: init %CompleteClass.3 = converted %.loc9_17.1, %.loc9_17.4 [template = constants.%struct]
  230. // CHECK:STDOUT: return %.loc9_18 to %return
  231. // CHECK:STDOUT: }
  232. // CHECK:STDOUT:
  233. // CHECK:STDOUT: --- use_foo.carbon
  234. // CHECK:STDOUT:
  235. // CHECK:STDOUT: constants {
  236. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  237. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  238. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  239. // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
  240. // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
  241. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  242. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  243. // CHECK:STDOUT: %.2: type = struct_type {.n: i32} [template]
  244. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass [template]
  245. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0, <unexpected instref inst+26> [symbolic]
  246. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, (i32) [template]
  247. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  248. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  249. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  250. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  251. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  252. // CHECK:STDOUT: }
  253. // CHECK:STDOUT:
  254. // CHECK:STDOUT: file {
  255. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  256. // CHECK:STDOUT: .Class = %import_ref.1
  257. // CHECK:STDOUT: .CompleteClass = %import_ref.2
  258. // CHECK:STDOUT: .F = %import_ref.3
  259. // CHECK:STDOUT: .Core = %Core
  260. // CHECK:STDOUT: .Use = %Use.decl
  261. // CHECK:STDOUT: }
  262. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+5, unloaded
  263. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref ir1, inst+12, loaded [template = constants.%CompleteClass.1]
  264. // CHECK:STDOUT: %import_ref.3: %F.type.1 = import_ref ir1, inst+48, loaded [template = constants.%F.1]
  265. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  266. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir4, inst+3, loaded [template = constants.%Int32]
  267. // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
  268. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  269. // CHECK:STDOUT: %.loc5_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  270. // CHECK:STDOUT: %.loc5_13.2: type = converted %int.make_type_32, %.loc5_13.1 [template = i32]
  271. // CHECK:STDOUT: @Use.%return: ref i32 = var <return slot>
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT: %import_ref.5 = import_ref ir1, inst+15, unloaded
  274. // CHECK:STDOUT: %import_ref.6 = import_ref ir1, inst+25, unloaded
  275. // CHECK:STDOUT: %import_ref.7: %F.type.2 = import_ref ir1, inst+33, loaded [template = constants.%F.2]
  276. // CHECK:STDOUT: %import_ref.8: %Int32.type = import_ref ir4, inst+3, loaded [template = constants.%Int32]
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT:
  279. // CHECK:STDOUT: class @CompleteClass {
  280. // CHECK:STDOUT: !members:
  281. // CHECK:STDOUT: .Self = file.%import_ref.5
  282. // CHECK:STDOUT: .n = file.%import_ref.6
  283. // CHECK:STDOUT: .F = file.%import_ref.7
  284. // CHECK:STDOUT: }
  285. // CHECK:STDOUT:
  286. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  287. // CHECK:STDOUT:
  288. // CHECK:STDOUT: fn @Use() -> i32 {
  289. // CHECK:STDOUT: !entry:
  290. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, file.%import_ref.2 [template = constants.%CompleteClass.1]
  291. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  292. // CHECK:STDOUT: %.loc6_23.1: type = value_of_initializer %int.make_type_32 [template = i32]
  293. // CHECK:STDOUT: %.loc6_23.2: type = converted %int.make_type_32, %.loc6_23.1 [template = i32]
  294. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, (%.loc6_23.2) [template = constants.%CompleteClass.3]
  295. // CHECK:STDOUT: %v.var: ref %CompleteClass.3 = var v
  296. // CHECK:STDOUT: %v: ref %CompleteClass.3 = bind_name v, %v.var
  297. // CHECK:STDOUT: %F.ref.loc6: %F.type.1 = name_ref F, file.%import_ref.3 [template = constants.%F.1]
  298. // CHECK:STDOUT: %.loc6_7: ref %CompleteClass.3 = splice_block %v.var {}
  299. // CHECK:STDOUT: %F.call.loc6: init %CompleteClass.3 = call %F.ref.loc6() to %.loc6_7
  300. // CHECK:STDOUT: assign %v.var, %F.call.loc6
  301. // CHECK:STDOUT: %v.ref: ref %CompleteClass.3 = name_ref v, %v
  302. // CHECK:STDOUT: %F.ref.loc7: %F.type.2 = name_ref F, file.%import_ref.7 [template = constants.%F.2]
  303. // CHECK:STDOUT: %F.call.loc7: init i32 = call %F.ref.loc7()
  304. // CHECK:STDOUT: %.loc7_15.1: i32 = value_of_initializer %F.call.loc7
  305. // CHECK:STDOUT: %.loc7_15.2: i32 = converted %F.call.loc7, %.loc7_15.1
  306. // CHECK:STDOUT: return %.loc7_15.2
  307. // CHECK:STDOUT: }
  308. // CHECK:STDOUT:
  309. // CHECK:STDOUT: fn @F.1() -> %CompleteClass.3;
  310. // CHECK:STDOUT:
  311. // CHECK:STDOUT: fn @F.2() -> i32;
  312. // CHECK:STDOUT:
  313. // CHECK:STDOUT: --- fail_todo_use_foo.carbon
  314. // CHECK:STDOUT:
  315. // CHECK:STDOUT: constants {
  316. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  317. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  318. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  319. // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
  320. // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
  321. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  322. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  323. // CHECK:STDOUT: %.2: type = struct_type {.n: i32} [template]
  324. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass [template]
  325. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0, <unexpected instref inst+26> [symbolic]
  326. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, (i32) [template]
  327. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  328. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  329. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  330. // CHECK:STDOUT: %.4: type = unbound_element_type %CompleteClass.2, i32 [template]
  331. // CHECK:STDOUT: }
  332. // CHECK:STDOUT:
  333. // CHECK:STDOUT: file {
  334. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  335. // CHECK:STDOUT: .Class = %import_ref.1
  336. // CHECK:STDOUT: .CompleteClass = %import_ref.2
  337. // CHECK:STDOUT: .F = %import_ref.3
  338. // CHECK:STDOUT: .Core = %Core
  339. // CHECK:STDOUT: .Use = %Use.decl
  340. // CHECK:STDOUT: }
  341. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+5, unloaded
  342. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref ir1, inst+12, loaded [template = constants.%CompleteClass.1]
  343. // CHECK:STDOUT: %import_ref.3: %F.type = import_ref ir1, inst+48, loaded [template = constants.%F]
  344. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  345. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir4, inst+3, loaded [template = constants.%Int32]
  346. // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
  347. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  348. // CHECK:STDOUT: %.loc5_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  349. // CHECK:STDOUT: %.loc5_13.2: type = converted %int.make_type_32, %.loc5_13.1 [template = i32]
  350. // CHECK:STDOUT: @Use.%return: ref i32 = var <return slot>
  351. // CHECK:STDOUT: }
  352. // CHECK:STDOUT: %import_ref.5 = import_ref ir1, inst+15, unloaded
  353. // CHECK:STDOUT: %import_ref.6: %.4 = import_ref ir1, inst+25, loaded [template = imports.%.1]
  354. // CHECK:STDOUT: %import_ref.7 = import_ref ir1, inst+33, unloaded
  355. // CHECK:STDOUT: %import_ref.8: %Int32.type = import_ref ir4, inst+3, loaded [template = constants.%Int32]
  356. // CHECK:STDOUT: }
  357. // CHECK:STDOUT:
  358. // CHECK:STDOUT: class @CompleteClass {
  359. // CHECK:STDOUT: !members:
  360. // CHECK:STDOUT: .Self = file.%import_ref.5
  361. // CHECK:STDOUT: .n = file.%import_ref.6
  362. // CHECK:STDOUT: .F = file.%import_ref.7
  363. // CHECK:STDOUT: }
  364. // CHECK:STDOUT:
  365. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  366. // CHECK:STDOUT:
  367. // CHECK:STDOUT: fn @Use() -> i32 {
  368. // CHECK:STDOUT: !entry:
  369. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, file.%import_ref.2 [template = constants.%CompleteClass.1]
  370. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  371. // CHECK:STDOUT: %.loc6_23.1: type = value_of_initializer %int.make_type_32 [template = i32]
  372. // CHECK:STDOUT: %.loc6_23.2: type = converted %int.make_type_32, %.loc6_23.1 [template = i32]
  373. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, (%.loc6_23.2) [template = constants.%CompleteClass.3]
  374. // CHECK:STDOUT: %v.var: ref %CompleteClass.3 = var v
  375. // CHECK:STDOUT: %v: ref %CompleteClass.3 = bind_name v, %v.var
  376. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%import_ref.3 [template = constants.%F]
  377. // CHECK:STDOUT: %.loc6_7: ref %CompleteClass.3 = splice_block %v.var {}
  378. // CHECK:STDOUT: %F.call: init %CompleteClass.3 = call %F.ref() to %.loc6_7
  379. // CHECK:STDOUT: assign %v.var, %F.call
  380. // CHECK:STDOUT: %v.ref: ref %CompleteClass.3 = name_ref v, %v
  381. // CHECK:STDOUT: %n.ref: %.4 = name_ref n, file.%import_ref.6 [template = imports.%.1]
  382. // CHECK:STDOUT: %.loc12: i32 = class_element_access <error>, element0 [template = <error>]
  383. // CHECK:STDOUT: return <error>
  384. // CHECK:STDOUT: }
  385. // CHECK:STDOUT:
  386. // CHECK:STDOUT: fn @F() -> %CompleteClass.3;
  387. // CHECK:STDOUT:
  388. // CHECK:STDOUT: --- fail_generic_arg_mismatch.carbon
  389. // CHECK:STDOUT:
  390. // CHECK:STDOUT: constants {
  391. // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
  392. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  393. // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
  394. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  395. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  396. // CHECK:STDOUT: %.2: type = struct_type {.n: i32} [template]
  397. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass [template]
  398. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0, <unexpected instref inst+17> [symbolic]
  399. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  400. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  401. // CHECK:STDOUT: %.3: type = ptr_type i32 [template]
  402. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, (%.3) [template]
  403. // CHECK:STDOUT: %.4: type = ptr_type %.2 [template]
  404. // CHECK:STDOUT: %CompleteClass.4: type = class_type @CompleteClass, (i32) [template]
  405. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  406. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  407. // CHECK:STDOUT: }
  408. // CHECK:STDOUT:
  409. // CHECK:STDOUT: file {
  410. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  411. // CHECK:STDOUT: .Class = %import_ref.1
  412. // CHECK:STDOUT: .CompleteClass = %import_ref.2
  413. // CHECK:STDOUT: .F = %import_ref.3
  414. // CHECK:STDOUT: .Core = %Core
  415. // CHECK:STDOUT: .Use = %Use.decl
  416. // CHECK:STDOUT: }
  417. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+5, unloaded
  418. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref ir1, inst+12, loaded [template = constants.%CompleteClass.1]
  419. // CHECK:STDOUT: %import_ref.3: %F.type = import_ref ir1, inst+48, loaded [template = constants.%F]
  420. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  421. // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {}
  422. // CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+15, unloaded
  423. // CHECK:STDOUT: %import_ref.5 = import_ref ir1, inst+25, unloaded
  424. // CHECK:STDOUT: %import_ref.6 = import_ref ir1, inst+33, unloaded
  425. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref ir4, inst+3, loaded [template = constants.%Int32]
  426. // CHECK:STDOUT: }
  427. // CHECK:STDOUT:
  428. // CHECK:STDOUT: class @CompleteClass {
  429. // CHECK:STDOUT: !members:
  430. // CHECK:STDOUT: .Self = file.%import_ref.4
  431. // CHECK:STDOUT: .n = file.%import_ref.5
  432. // CHECK:STDOUT: .F = file.%import_ref.6
  433. // CHECK:STDOUT: }
  434. // CHECK:STDOUT:
  435. // CHECK:STDOUT: fn @Use() {
  436. // CHECK:STDOUT: !entry:
  437. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, file.%import_ref.2 [template = constants.%CompleteClass.1]
  438. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  439. // CHECK:STDOUT: %.loc11_27.1: type = value_of_initializer %int.make_type_32 [template = i32]
  440. // CHECK:STDOUT: %.loc11_27.2: type = converted %int.make_type_32, %.loc11_27.1 [template = i32]
  441. // CHECK:STDOUT: %.loc11_27.3: type = ptr_type i32 [template = constants.%.3]
  442. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, (%.loc11_27.3) [template = constants.%CompleteClass.3]
  443. // CHECK:STDOUT: %v.var: ref %CompleteClass.3 = var v
  444. // CHECK:STDOUT: %v: ref %CompleteClass.3 = bind_name v, %v.var
  445. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%import_ref.3 [template = constants.%F]
  446. // CHECK:STDOUT: %.loc11_33: ref %CompleteClass.4 = temporary_storage
  447. // CHECK:STDOUT: %F.call: init %CompleteClass.4 = call %F.ref() to %.loc11_33
  448. // CHECK:STDOUT: assign %v.var, <error>
  449. // CHECK:STDOUT: return
  450. // CHECK:STDOUT: }
  451. // CHECK:STDOUT:
  452. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  453. // CHECK:STDOUT:
  454. // CHECK:STDOUT: fn @F() -> %CompleteClass.4;
  455. // CHECK:STDOUT:
  456. // CHECK:STDOUT: --- fail_bad_foo.impl.carbon
  457. // CHECK:STDOUT:
  458. // CHECK:STDOUT: constants {
  459. // CHECK:STDOUT: %U: type = bind_symbolic_name U 0 [symbolic]
  460. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  461. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  462. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  463. // CHECK:STDOUT: %Class.2: type = class_type @Class [template]
  464. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0, <unexpected instref inst+14> [symbolic]
  465. // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
  466. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  467. // CHECK:STDOUT: %.3: type = class_type @.1 [template]
  468. // CHECK:STDOUT: }
  469. // CHECK:STDOUT:
  470. // CHECK:STDOUT: file {
  471. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  472. // CHECK:STDOUT: .Class = %import_ref.1
  473. // CHECK:STDOUT: .CompleteClass = %import_ref.2
  474. // CHECK:STDOUT: .F = %import_ref.3
  475. // CHECK:STDOUT: .Core = %Core
  476. // CHECK:STDOUT: }
  477. // CHECK:STDOUT: %import_ref.1: %Class.type = import_ref ir0, inst+5, loaded [template = constants.%Class.1]
  478. // CHECK:STDOUT: %import_ref.2 = import_ref ir0, inst+12, unloaded
  479. // CHECK:STDOUT: %import_ref.3 = import_ref ir0, inst+48, unloaded
  480. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  481. // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
  482. // CHECK:STDOUT: %U.loc9_13.1: type = param U
  483. // CHECK:STDOUT: %U.loc9_13.2: type = bind_symbolic_name U 0, %U.loc9_13.1 [symbolic = constants.%U]
  484. // CHECK:STDOUT: }
  485. // CHECK:STDOUT: }
  486. // CHECK:STDOUT:
  487. // CHECK:STDOUT: class @Class;
  488. // CHECK:STDOUT:
  489. // CHECK:STDOUT: class @.1 {
  490. // CHECK:STDOUT: %T.ref: <error> = name_ref T, <error> [template = <error>]
  491. // CHECK:STDOUT: %.loc13: <error> = field_decl x, element0 [template]
  492. // CHECK:STDOUT:
  493. // CHECK:STDOUT: !members:
  494. // CHECK:STDOUT: .Self = constants.%.3
  495. // CHECK:STDOUT: .x = %.loc13
  496. // CHECK:STDOUT: }
  497. // CHECK:STDOUT: