virtual_modifiers.carbon 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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/virtual_modifiers.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/virtual_modifiers.carbon
  10. // --- modifiers.carbon
  11. package Modifiers;
  12. base class Base {
  13. virtual fn H();
  14. impl fn I();
  15. }
  16. abstract class Abstract {
  17. abstract fn J();
  18. virtual fn K();
  19. impl fn L();
  20. }
  21. // --- todo_fail_later_base.carbon
  22. package FailLaterBase;
  23. import Modifiers;
  24. base class Derived {
  25. virtual fn F();
  26. extend base: Modifiers.Base;
  27. }
  28. // --- init.carbon
  29. package Init;
  30. import Modifiers;
  31. fn F() {
  32. var v: Modifiers.Base = {};
  33. }
  34. // --- init_members.carbon
  35. package InitMembers;
  36. base class Base {
  37. var m1: i32;
  38. var m2: i32;
  39. virtual fn F();
  40. }
  41. fn F() {
  42. var i: i32 = 3;
  43. // TODO: These should initialize element1 (.m), not element0 (the vptr)
  44. var b1: Base = {.m2 = i, .m1 = i};
  45. var b2: Base = {.m2 = 3, .m1 = 5};
  46. // This one is good, though.
  47. b1.m2 = 4;
  48. }
  49. // --- todo_fail_impl_without_base_declaration.carbon
  50. package ImplWithoutBaseDeclaration;
  51. base class Base {
  52. }
  53. class Derived {
  54. extend base: Base;
  55. impl fn F();
  56. }
  57. // CHECK:STDOUT: --- modifiers.carbon
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: constants {
  60. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  61. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  62. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  63. // CHECK:STDOUT: %I.type: type = fn_type @I [template]
  64. // CHECK:STDOUT: %I: %I.type = struct_value () [template]
  65. // CHECK:STDOUT: %.1: type = ptr_type <vtable> [template]
  66. // CHECK:STDOUT: %.2: type = struct_type {.<vptr>: %.1} [template]
  67. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  68. // CHECK:STDOUT: %Abstract: type = class_type @Abstract [template]
  69. // CHECK:STDOUT: %J.type: type = fn_type @J [template]
  70. // CHECK:STDOUT: %J: %J.type = struct_value () [template]
  71. // CHECK:STDOUT: %K.type: type = fn_type @K [template]
  72. // CHECK:STDOUT: %K: %K.type = struct_value () [template]
  73. // CHECK:STDOUT: %L.type: type = fn_type @L [template]
  74. // CHECK:STDOUT: %L: %L.type = struct_value () [template]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: imports {
  78. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  79. // CHECK:STDOUT: import Core//prelude
  80. // CHECK:STDOUT: import Core//prelude/...
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: file {
  85. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  86. // CHECK:STDOUT: .Core = imports.%Core
  87. // CHECK:STDOUT: .Base = %Base.decl
  88. // CHECK:STDOUT: .Abstract = %Abstract.decl
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %Core.import = import Core
  91. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {} {}
  92. // CHECK:STDOUT: %Abstract.decl: type = class_decl @Abstract [template = constants.%Abstract] {} {}
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: class @Base {
  96. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
  97. // CHECK:STDOUT: %I.decl: %I.type = fn_decl @I [template = constants.%I] {} {}
  98. // CHECK:STDOUT: %.loc8: <witness> = complete_type_witness %.2 [template = constants.%.3]
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: !members:
  101. // CHECK:STDOUT: .Self = constants.%Base
  102. // CHECK:STDOUT: .H = %H.decl
  103. // CHECK:STDOUT: .I = %I.decl
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: class @Abstract {
  107. // CHECK:STDOUT: %J.decl: %J.type = fn_decl @J [template = constants.%J] {} {}
  108. // CHECK:STDOUT: %K.decl: %K.type = fn_decl @K [template = constants.%K] {} {}
  109. // CHECK:STDOUT: %L.decl: %L.type = fn_decl @L [template = constants.%L] {} {}
  110. // CHECK:STDOUT: %.loc16: <witness> = complete_type_witness %.2 [template = constants.%.3]
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: !members:
  113. // CHECK:STDOUT: .Self = constants.%Abstract
  114. // CHECK:STDOUT: .J = %J.decl
  115. // CHECK:STDOUT: .K = %K.decl
  116. // CHECK:STDOUT: .L = %L.decl
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: virtual fn @H();
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: impl fn @I();
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: abstract fn @J();
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: virtual fn @K();
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: impl fn @L();
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: --- todo_fail_later_base.carbon
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: constants {
  132. // CHECK:STDOUT: %Derived: type = class_type @Derived [template]
  133. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  134. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  135. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  136. // CHECK:STDOUT: %.5: type = unbound_element_type %Derived, %Base [template]
  137. // CHECK:STDOUT: %.6: type = struct_type {.base: %Base} [template]
  138. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: imports {
  142. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  143. // CHECK:STDOUT: import Core//prelude
  144. // CHECK:STDOUT: import Core//prelude/...
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT: %Modifiers: <namespace> = namespace file.%Modifiers.import, [template] {
  147. // CHECK:STDOUT: .Base = %import_ref.1
  148. // CHECK:STDOUT: import Modifiers//default
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: %import_ref.1: type = import_ref Modifiers//default, inst+3, loaded [template = constants.%Base]
  151. // CHECK:STDOUT: %import_ref.2 = import_ref Modifiers//default, inst+4, unloaded
  152. // CHECK:STDOUT: %import_ref.3 = import_ref Modifiers//default, inst+5, unloaded
  153. // CHECK:STDOUT: %import_ref.4 = import_ref Modifiers//default, inst+9, unloaded
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: file {
  157. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  158. // CHECK:STDOUT: .Core = imports.%Core
  159. // CHECK:STDOUT: .Modifiers = imports.%Modifiers
  160. // CHECK:STDOUT: .Derived = %Derived.decl
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT: %Core.import = import Core
  163. // CHECK:STDOUT: %Modifiers.import = import Modifiers
  164. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [template = constants.%Derived] {} {}
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: class @Derived {
  168. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  169. // CHECK:STDOUT: %Modifiers.ref: <namespace> = name_ref Modifiers, imports.%Modifiers [template = imports.%Modifiers]
  170. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%import_ref.1 [template = constants.%Base]
  171. // CHECK:STDOUT: %.loc8: %.5 = base_decl %Base, element0 [template]
  172. // CHECK:STDOUT: %.loc9: <witness> = complete_type_witness %.6 [template = constants.%.7]
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: !members:
  175. // CHECK:STDOUT: .Self = constants.%Derived
  176. // CHECK:STDOUT: .F = %F.decl
  177. // CHECK:STDOUT: .base = %.loc8
  178. // CHECK:STDOUT: extend %Base.ref
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: class @Base {
  182. // CHECK:STDOUT: !members:
  183. // CHECK:STDOUT: .Self = imports.%import_ref.2
  184. // CHECK:STDOUT: .H = imports.%import_ref.3
  185. // CHECK:STDOUT: .I = imports.%import_ref.4
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: virtual fn @F();
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: --- init.carbon
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: constants {
  193. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  194. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  195. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  196. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: imports {
  200. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  201. // CHECK:STDOUT: import Core//prelude
  202. // CHECK:STDOUT: import Core//prelude/...
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT: %Modifiers: <namespace> = namespace file.%Modifiers.import, [template] {
  205. // CHECK:STDOUT: .Base = %import_ref.1
  206. // CHECK:STDOUT: import Modifiers//default
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT: %import_ref.1: type = import_ref Modifiers//default, inst+3, loaded [template = constants.%Base]
  209. // CHECK:STDOUT: %import_ref.2 = import_ref Modifiers//default, inst+4, unloaded
  210. // CHECK:STDOUT: %import_ref.3 = import_ref Modifiers//default, inst+5, unloaded
  211. // CHECK:STDOUT: %import_ref.4 = import_ref Modifiers//default, inst+9, unloaded
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: file {
  215. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  216. // CHECK:STDOUT: .Core = imports.%Core
  217. // CHECK:STDOUT: .Modifiers = imports.%Modifiers
  218. // CHECK:STDOUT: .F = %F.decl
  219. // CHECK:STDOUT: }
  220. // CHECK:STDOUT: %Core.import = import Core
  221. // CHECK:STDOUT: %Modifiers.import = import Modifiers
  222. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  223. // CHECK:STDOUT: }
  224. // CHECK:STDOUT:
  225. // CHECK:STDOUT: class @Base {
  226. // CHECK:STDOUT: !members:
  227. // CHECK:STDOUT: .Self = imports.%import_ref.2
  228. // CHECK:STDOUT: .H = imports.%import_ref.3
  229. // CHECK:STDOUT: .I = imports.%import_ref.4
  230. // CHECK:STDOUT: }
  231. // CHECK:STDOUT:
  232. // CHECK:STDOUT: fn @F() {
  233. // CHECK:STDOUT: !entry:
  234. // CHECK:STDOUT: %Modifiers.ref: <namespace> = name_ref Modifiers, imports.%Modifiers [template = imports.%Modifiers]
  235. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%import_ref.1 [template = constants.%Base]
  236. // CHECK:STDOUT: %v.var: ref %Base = var v
  237. // CHECK:STDOUT: %v: ref %Base = bind_name v, %v.var
  238. // CHECK:STDOUT: %.loc7_28.1: %.5 = struct_literal ()
  239. // CHECK:STDOUT: %.loc7_28.2: init %Base = class_init (<error>), %v.var [template = <error>]
  240. // CHECK:STDOUT: %.loc7_29: init %Base = converted %.loc7_28.1, %.loc7_28.2 [template = <error>]
  241. // CHECK:STDOUT: assign %v.var, %.loc7_29
  242. // CHECK:STDOUT: return
  243. // CHECK:STDOUT: }
  244. // CHECK:STDOUT:
  245. // CHECK:STDOUT: --- init_members.carbon
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: constants {
  248. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  249. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  250. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  251. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  252. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  253. // CHECK:STDOUT: %.2: type = unbound_element_type %Base, %i32 [template]
  254. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  255. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  256. // CHECK:STDOUT: %.3: type = ptr_type <vtable> [template]
  257. // CHECK:STDOUT: %.4: type = struct_type {.<vptr>: %.3, .m1: %i32, .m2: %i32} [template]
  258. // CHECK:STDOUT: %.5: <witness> = complete_type_witness %.4 [template]
  259. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  260. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  261. // CHECK:STDOUT: %.6: Core.IntLiteral = int_value 3 [template]
  262. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  263. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  264. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  265. // CHECK:STDOUT: %.30: <witness> = interface_witness (%Convert.14) [template]
  266. // CHECK:STDOUT: %.31: <bound method> = bound_method %.6, %Convert.14 [template]
  267. // CHECK:STDOUT: %.32: <specific function> = specific_function %.31, @Convert.2(%.1) [template]
  268. // CHECK:STDOUT: %.33: %i32 = int_value 3 [template]
  269. // CHECK:STDOUT: %.35: type = struct_type {.m2: %i32, .m1: %i32} [template]
  270. // CHECK:STDOUT: %.36: Core.IntLiteral = int_value 5 [template]
  271. // CHECK:STDOUT: %.37: type = struct_type {.m2: Core.IntLiteral, .m1: Core.IntLiteral} [template]
  272. // CHECK:STDOUT: %.38: <bound method> = bound_method %.36, %Convert.14 [template]
  273. // CHECK:STDOUT: %.39: <specific function> = specific_function %.38, @Convert.2(%.1) [template]
  274. // CHECK:STDOUT: %.40: %i32 = int_value 5 [template]
  275. // CHECK:STDOUT: %.41: Core.IntLiteral = int_value 4 [template]
  276. // CHECK:STDOUT: %.42: <bound method> = bound_method %.41, %Convert.14 [template]
  277. // CHECK:STDOUT: %.43: <specific function> = specific_function %.42, @Convert.2(%.1) [template]
  278. // CHECK:STDOUT: %.44: %i32 = int_value 4 [template]
  279. // CHECK:STDOUT: }
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: imports {
  282. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  283. // CHECK:STDOUT: .Int = %import_ref.1
  284. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  285. // CHECK:STDOUT: import Core//prelude
  286. // CHECK:STDOUT: import Core//prelude/...
  287. // CHECK:STDOUT: }
  288. // CHECK:STDOUT: }
  289. // CHECK:STDOUT:
  290. // CHECK:STDOUT: file {
  291. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  292. // CHECK:STDOUT: .Core = imports.%Core
  293. // CHECK:STDOUT: .Base = %Base.decl
  294. // CHECK:STDOUT: .F = %F.decl
  295. // CHECK:STDOUT: }
  296. // CHECK:STDOUT: %Core.import = import Core
  297. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {} {}
  298. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {}
  299. // CHECK:STDOUT: }
  300. // CHECK:STDOUT:
  301. // CHECK:STDOUT: class @Base {
  302. // CHECK:STDOUT: %.loc5_11.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  303. // CHECK:STDOUT: %int.make_type_signed.loc5: init type = call constants.%Int(%.loc5_11.1) [template = constants.%i32]
  304. // CHECK:STDOUT: %.loc5_11.2: type = value_of_initializer %int.make_type_signed.loc5 [template = constants.%i32]
  305. // CHECK:STDOUT: %.loc5_11.3: type = converted %int.make_type_signed.loc5, %.loc5_11.2 [template = constants.%i32]
  306. // CHECK:STDOUT: %.loc5_9: %.2 = field_decl m1, element1 [template]
  307. // CHECK:STDOUT: %.loc6_11.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  308. // CHECK:STDOUT: %int.make_type_signed.loc6: init type = call constants.%Int(%.loc6_11.1) [template = constants.%i32]
  309. // CHECK:STDOUT: %.loc6_11.2: type = value_of_initializer %int.make_type_signed.loc6 [template = constants.%i32]
  310. // CHECK:STDOUT: %.loc6_11.3: type = converted %int.make_type_signed.loc6, %.loc6_11.2 [template = constants.%i32]
  311. // CHECK:STDOUT: %.loc6_9: %.2 = field_decl m2, element2 [template]
  312. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  313. // CHECK:STDOUT: %.loc9: <witness> = complete_type_witness %.4 [template = constants.%.5]
  314. // CHECK:STDOUT:
  315. // CHECK:STDOUT: !members:
  316. // CHECK:STDOUT: .Self = constants.%Base
  317. // CHECK:STDOUT: .m1 = %.loc5_9
  318. // CHECK:STDOUT: .m2 = %.loc6_9
  319. // CHECK:STDOUT: .F = %F.decl
  320. // CHECK:STDOUT: }
  321. // CHECK:STDOUT:
  322. // CHECK:STDOUT: virtual fn @F.1();
  323. // CHECK:STDOUT:
  324. // CHECK:STDOUT: fn @F.2() {
  325. // CHECK:STDOUT: !entry:
  326. // CHECK:STDOUT: %.loc12_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  327. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc12_10.1) [template = constants.%i32]
  328. // CHECK:STDOUT: %.loc12_10.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  329. // CHECK:STDOUT: %.loc12_10.3: type = converted %int.make_type_signed, %.loc12_10.2 [template = constants.%i32]
  330. // CHECK:STDOUT: %i.var: ref %i32 = var i
  331. // CHECK:STDOUT: %i: ref %i32 = bind_name i, %i.var
  332. // CHECK:STDOUT: %.loc12_16: Core.IntLiteral = int_value 3 [template = constants.%.6]
  333. // CHECK:STDOUT: %.loc12_17.1: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  334. // CHECK:STDOUT: %.loc12_17.2: <bound method> = bound_method %.loc12_16, %.loc12_17.1 [template = constants.%.31]
  335. // CHECK:STDOUT: %.loc12_17.3: <specific function> = specific_function %.loc12_17.2, @Convert.2(constants.%.1) [template = constants.%.32]
  336. // CHECK:STDOUT: %int.convert_checked.loc12: init %i32 = call %.loc12_17.3(%.loc12_16) [template = constants.%.33]
  337. // CHECK:STDOUT: %.loc12_17.4: init %i32 = converted %.loc12_16, %int.convert_checked.loc12 [template = constants.%.33]
  338. // CHECK:STDOUT: assign %i.var, %.loc12_17.4
  339. // CHECK:STDOUT: %Base.ref.loc14: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  340. // CHECK:STDOUT: %b1.var: ref %Base = var b1
  341. // CHECK:STDOUT: %b1: ref %Base = bind_name b1, %b1.var
  342. // CHECK:STDOUT: %i.ref.loc14_25: ref %i32 = name_ref i, %i
  343. // CHECK:STDOUT: %i.ref.loc14_34: ref %i32 = name_ref i, %i
  344. // CHECK:STDOUT: %.loc14_35.1: %.35 = struct_literal (%i.ref.loc14_25, %i.ref.loc14_34)
  345. // CHECK:STDOUT: %.loc14_34: %i32 = bind_value %i.ref.loc14_34
  346. // CHECK:STDOUT: %.loc14_35.2: ref %i32 = class_element_access %b1.var, element2
  347. // CHECK:STDOUT: %.loc14_35.3: init %i32 = initialize_from %.loc14_34 to %.loc14_35.2
  348. // CHECK:STDOUT: %.loc14_25: %i32 = bind_value %i.ref.loc14_25
  349. // CHECK:STDOUT: %.loc14_35.4: ref %i32 = class_element_access %b1.var, element1
  350. // CHECK:STDOUT: %.loc14_35.5: init %i32 = initialize_from %.loc14_25 to %.loc14_35.4
  351. // CHECK:STDOUT: %.loc14_35.6: init %Base = class_init (<error>, %.loc14_35.3, %.loc14_35.5), %b1.var
  352. // CHECK:STDOUT: %.loc14_36: init %Base = converted %.loc14_35.1, %.loc14_35.6
  353. // CHECK:STDOUT: assign %b1.var, %.loc14_36
  354. // CHECK:STDOUT: %Base.ref.loc15: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  355. // CHECK:STDOUT: %b2.var: ref %Base = var b2
  356. // CHECK:STDOUT: %b2: ref %Base = bind_name b2, %b2.var
  357. // CHECK:STDOUT: %.loc15_25: Core.IntLiteral = int_value 3 [template = constants.%.6]
  358. // CHECK:STDOUT: %.loc15_34: Core.IntLiteral = int_value 5 [template = constants.%.36]
  359. // CHECK:STDOUT: %.loc15_35.1: %.37 = struct_literal (%.loc15_25, %.loc15_34)
  360. // CHECK:STDOUT: %.loc15_35.2: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  361. // CHECK:STDOUT: %.loc15_35.3: <bound method> = bound_method %.loc15_34, %.loc15_35.2 [template = constants.%.38]
  362. // CHECK:STDOUT: %.loc15_35.4: <specific function> = specific_function %.loc15_35.3, @Convert.2(constants.%.1) [template = constants.%.39]
  363. // CHECK:STDOUT: %int.convert_checked.loc15_35.1: init %i32 = call %.loc15_35.4(%.loc15_34) [template = constants.%.40]
  364. // CHECK:STDOUT: %.loc15_35.5: init %i32 = converted %.loc15_34, %int.convert_checked.loc15_35.1 [template = constants.%.40]
  365. // CHECK:STDOUT: %.loc15_35.6: ref %i32 = class_element_access %b2.var, element2
  366. // CHECK:STDOUT: %.loc15_35.7: init %i32 = initialize_from %.loc15_35.5 to %.loc15_35.6 [template = constants.%.40]
  367. // CHECK:STDOUT: %.loc15_35.8: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  368. // CHECK:STDOUT: %.loc15_35.9: <bound method> = bound_method %.loc15_25, %.loc15_35.8 [template = constants.%.31]
  369. // CHECK:STDOUT: %.loc15_35.10: <specific function> = specific_function %.loc15_35.9, @Convert.2(constants.%.1) [template = constants.%.32]
  370. // CHECK:STDOUT: %int.convert_checked.loc15_35.2: init %i32 = call %.loc15_35.10(%.loc15_25) [template = constants.%.33]
  371. // CHECK:STDOUT: %.loc15_35.11: init %i32 = converted %.loc15_25, %int.convert_checked.loc15_35.2 [template = constants.%.33]
  372. // CHECK:STDOUT: %.loc15_35.12: ref %i32 = class_element_access %b2.var, element1
  373. // CHECK:STDOUT: %.loc15_35.13: init %i32 = initialize_from %.loc15_35.11 to %.loc15_35.12 [template = constants.%.33]
  374. // CHECK:STDOUT: %.loc15_35.14: init %Base = class_init (<error>, %.loc15_35.7, %.loc15_35.13), %b2.var [template = <error>]
  375. // CHECK:STDOUT: %.loc15_36: init %Base = converted %.loc15_35.1, %.loc15_35.14 [template = <error>]
  376. // CHECK:STDOUT: assign %b2.var, %.loc15_36
  377. // CHECK:STDOUT: %b1.ref: ref %Base = name_ref b1, %b1
  378. // CHECK:STDOUT: %m2.ref: %.2 = name_ref m2, @Base.%.loc6_9 [template = @Base.%.loc6_9]
  379. // CHECK:STDOUT: %.loc18_5: ref %i32 = class_element_access %b1.ref, element2
  380. // CHECK:STDOUT: %.loc18_11: Core.IntLiteral = int_value 4 [template = constants.%.41]
  381. // CHECK:STDOUT: %.loc18_9.1: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  382. // CHECK:STDOUT: %.loc18_9.2: <bound method> = bound_method %.loc18_11, %.loc18_9.1 [template = constants.%.42]
  383. // CHECK:STDOUT: %.loc18_9.3: <specific function> = specific_function %.loc18_9.2, @Convert.2(constants.%.1) [template = constants.%.43]
  384. // CHECK:STDOUT: %int.convert_checked.loc18: init %i32 = call %.loc18_9.3(%.loc18_11) [template = constants.%.44]
  385. // CHECK:STDOUT: %.loc18_9.4: init %i32 = converted %.loc18_11, %int.convert_checked.loc18 [template = constants.%.44]
  386. // CHECK:STDOUT: assign %.loc18_5, %.loc18_9.4
  387. // CHECK:STDOUT: return
  388. // CHECK:STDOUT: }
  389. // CHECK:STDOUT:
  390. // CHECK:STDOUT: --- todo_fail_impl_without_base_declaration.carbon
  391. // CHECK:STDOUT:
  392. // CHECK:STDOUT: constants {
  393. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  394. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  395. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  396. // CHECK:STDOUT: %Derived: type = class_type @Derived [template]
  397. // CHECK:STDOUT: %.4: type = unbound_element_type %Derived, %Base [template]
  398. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  399. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  400. // CHECK:STDOUT: %.5: type = ptr_type <vtable> [template]
  401. // CHECK:STDOUT: %.6: type = struct_type {.<vptr>: %.5, .base: %Base} [template]
  402. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  403. // CHECK:STDOUT: }
  404. // CHECK:STDOUT:
  405. // CHECK:STDOUT: imports {
  406. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  407. // CHECK:STDOUT: import Core//prelude
  408. // CHECK:STDOUT: import Core//prelude/...
  409. // CHECK:STDOUT: }
  410. // CHECK:STDOUT: }
  411. // CHECK:STDOUT:
  412. // CHECK:STDOUT: file {
  413. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  414. // CHECK:STDOUT: .Core = imports.%Core
  415. // CHECK:STDOUT: .Base = %Base.decl
  416. // CHECK:STDOUT: .Derived = %Derived.decl
  417. // CHECK:STDOUT: }
  418. // CHECK:STDOUT: %Core.import = import Core
  419. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {} {}
  420. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [template = constants.%Derived] {} {}
  421. // CHECK:STDOUT: }
  422. // CHECK:STDOUT:
  423. // CHECK:STDOUT: class @Base {
  424. // CHECK:STDOUT: %.loc5: <witness> = complete_type_witness %.1 [template = constants.%.2]
  425. // CHECK:STDOUT:
  426. // CHECK:STDOUT: !members:
  427. // CHECK:STDOUT: .Self = constants.%Base
  428. // CHECK:STDOUT: }
  429. // CHECK:STDOUT:
  430. // CHECK:STDOUT: class @Derived {
  431. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  432. // CHECK:STDOUT: %.loc8: %.4 = base_decl %Base, element1 [template]
  433. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  434. // CHECK:STDOUT: %.loc10: <witness> = complete_type_witness %.6 [template = constants.%.7]
  435. // CHECK:STDOUT:
  436. // CHECK:STDOUT: !members:
  437. // CHECK:STDOUT: .Self = constants.%Derived
  438. // CHECK:STDOUT: .base = %.loc8
  439. // CHECK:STDOUT: .F = %F.decl
  440. // CHECK:STDOUT: extend %Base.ref
  441. // CHECK:STDOUT: }
  442. // CHECK:STDOUT:
  443. // CHECK:STDOUT: impl fn @F();
  444. // CHECK:STDOUT: