virtual_modifiers.carbon 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. }
  15. abstract class Abstract {
  16. abstract fn J();
  17. virtual fn K();
  18. }
  19. // --- todo_fail_later_base.carbon
  20. package FailLaterBase;
  21. import Modifiers;
  22. base class Derived {
  23. virtual fn F();
  24. extend base: Modifiers.Base;
  25. }
  26. // --- init.carbon
  27. package Init;
  28. import Modifiers;
  29. fn F() {
  30. var v: Modifiers.Base = {};
  31. }
  32. // --- impl_abstract.carbon
  33. package ImplAbstract;
  34. abstract class A1 {
  35. virtual fn F();
  36. }
  37. abstract class A2 {
  38. extend base: A1;
  39. impl fn F();
  40. }
  41. // --- impl_base.carbon
  42. package ImplBase;
  43. base class B1 {
  44. virtual fn F();
  45. }
  46. base class B2 {
  47. extend base: B1;
  48. impl fn F();
  49. }
  50. class C {
  51. extend base: B2;
  52. impl fn F();
  53. }
  54. // --- fail_modifiers.carbon
  55. package FailModifiers;
  56. class C {
  57. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+3]]:3: error: impl without base class [ImplWithoutBase]
  58. // CHECK:STDERR: impl fn F();
  59. // CHECK:STDERR: ^~~~~~~~~~~~
  60. impl fn F();
  61. }
  62. // --- init_members.carbon
  63. package InitMembers;
  64. base class Base {
  65. var m1: i32;
  66. var m2: i32;
  67. virtual fn F();
  68. }
  69. fn F() {
  70. var i: i32 = 3;
  71. // TODO: These should initialize element1 (.m), not element0 (the vptr)
  72. var b1: Base = {.m2 = i, .m1 = i};
  73. var b2: Base = {.m2 = 3, .m1 = 5};
  74. // This one is good, though.
  75. b1.m2 = 4;
  76. }
  77. // --- todo_fail_impl_without_base_declaration.carbon
  78. package ImplWithoutBaseDeclaration;
  79. base class Base {
  80. }
  81. class Derived {
  82. extend base: Base;
  83. impl fn F();
  84. }
  85. // CHECK:STDOUT: --- modifiers.carbon
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: constants {
  88. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  89. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  90. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  91. // CHECK:STDOUT: %.1: type = ptr_type <vtable> [template]
  92. // CHECK:STDOUT: %.2: type = struct_type {.<vptr>: %.1} [template]
  93. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  94. // CHECK:STDOUT: %Abstract: type = class_type @Abstract [template]
  95. // CHECK:STDOUT: %J.type: type = fn_type @J [template]
  96. // CHECK:STDOUT: %J: %J.type = struct_value () [template]
  97. // CHECK:STDOUT: %K.type: type = fn_type @K [template]
  98. // CHECK:STDOUT: %K: %K.type = struct_value () [template]
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: imports {
  102. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  103. // CHECK:STDOUT: import Core//prelude
  104. // CHECK:STDOUT: import Core//prelude/...
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: file {
  109. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  110. // CHECK:STDOUT: .Core = imports.%Core
  111. // CHECK:STDOUT: .Base = %Base.decl
  112. // CHECK:STDOUT: .Abstract = %Abstract.decl
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %Core.import = import Core
  115. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {} {}
  116. // CHECK:STDOUT: %Abstract.decl: type = class_decl @Abstract [template = constants.%Abstract] {} {}
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: class @Base {
  120. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
  121. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.2 [template = constants.%.3]
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: !members:
  124. // CHECK:STDOUT: .Self = constants.%Base
  125. // CHECK:STDOUT: .H = %H.decl
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: class @Abstract {
  129. // CHECK:STDOUT: %J.decl: %J.type = fn_decl @J [template = constants.%J] {} {}
  130. // CHECK:STDOUT: %K.decl: %K.type = fn_decl @K [template = constants.%K] {} {}
  131. // CHECK:STDOUT: %.loc12: <witness> = complete_type_witness %.2 [template = constants.%.3]
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: !members:
  134. // CHECK:STDOUT: .Self = constants.%Abstract
  135. // CHECK:STDOUT: .J = %J.decl
  136. // CHECK:STDOUT: .K = %K.decl
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: virtual fn @H();
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: abstract fn @J();
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: virtual fn @K();
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: --- todo_fail_later_base.carbon
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: constants {
  148. // CHECK:STDOUT: %Derived: type = class_type @Derived [template]
  149. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  150. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  151. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  152. // CHECK:STDOUT: %.5: type = unbound_element_type %Derived, %Base [template]
  153. // CHECK:STDOUT: %.6: type = struct_type {.base: %Base} [template]
  154. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: imports {
  158. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  159. // CHECK:STDOUT: import Core//prelude
  160. // CHECK:STDOUT: import Core//prelude/...
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT: %Modifiers: <namespace> = namespace file.%Modifiers.import, [template] {
  163. // CHECK:STDOUT: .Base = %import_ref.1
  164. // CHECK:STDOUT: import Modifiers//default
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT: %import_ref.1: type = import_ref Modifiers//default, inst+3, loaded [template = constants.%Base]
  167. // CHECK:STDOUT: %import_ref.2 = import_ref Modifiers//default, inst+4, unloaded
  168. // CHECK:STDOUT: %import_ref.3 = import_ref Modifiers//default, inst+5, unloaded
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: file {
  172. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  173. // CHECK:STDOUT: .Core = imports.%Core
  174. // CHECK:STDOUT: .Modifiers = imports.%Modifiers
  175. // CHECK:STDOUT: .Derived = %Derived.decl
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT: %Core.import = import Core
  178. // CHECK:STDOUT: %Modifiers.import = import Modifiers
  179. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [template = constants.%Derived] {} {}
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: class @Derived {
  183. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  184. // CHECK:STDOUT: %Modifiers.ref: <namespace> = name_ref Modifiers, imports.%Modifiers [template = imports.%Modifiers]
  185. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%import_ref.1 [template = constants.%Base]
  186. // CHECK:STDOUT: %.loc8: %.5 = base_decl %Base.ref, element0 [template]
  187. // CHECK:STDOUT: %.loc9: <witness> = complete_type_witness %.6 [template = constants.%.7]
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: !members:
  190. // CHECK:STDOUT: .Self = constants.%Derived
  191. // CHECK:STDOUT: .F = %F.decl
  192. // CHECK:STDOUT: .base = %.loc8
  193. // CHECK:STDOUT: extend %Base.ref
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: class @Base {
  197. // CHECK:STDOUT: !members:
  198. // CHECK:STDOUT: .Self = imports.%import_ref.2
  199. // CHECK:STDOUT: .H = imports.%import_ref.3
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: virtual fn @F();
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: --- init.carbon
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: constants {
  207. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  208. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  209. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  210. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  211. // CHECK:STDOUT: }
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: imports {
  214. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  215. // CHECK:STDOUT: import Core//prelude
  216. // CHECK:STDOUT: import Core//prelude/...
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT: %Modifiers: <namespace> = namespace file.%Modifiers.import, [template] {
  219. // CHECK:STDOUT: .Base = %import_ref.1
  220. // CHECK:STDOUT: import Modifiers//default
  221. // CHECK:STDOUT: }
  222. // CHECK:STDOUT: %import_ref.1: type = import_ref Modifiers//default, inst+3, loaded [template = constants.%Base]
  223. // CHECK:STDOUT: %import_ref.2 = import_ref Modifiers//default, inst+4, unloaded
  224. // CHECK:STDOUT: %import_ref.3 = import_ref Modifiers//default, inst+5, unloaded
  225. // CHECK:STDOUT: }
  226. // CHECK:STDOUT:
  227. // CHECK:STDOUT: file {
  228. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  229. // CHECK:STDOUT: .Core = imports.%Core
  230. // CHECK:STDOUT: .Modifiers = imports.%Modifiers
  231. // CHECK:STDOUT: .F = %F.decl
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT: %Core.import = import Core
  234. // CHECK:STDOUT: %Modifiers.import = import Modifiers
  235. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT:
  238. // CHECK:STDOUT: class @Base {
  239. // CHECK:STDOUT: !members:
  240. // CHECK:STDOUT: .Self = imports.%import_ref.2
  241. // CHECK:STDOUT: .H = imports.%import_ref.3
  242. // CHECK:STDOUT: }
  243. // CHECK:STDOUT:
  244. // CHECK:STDOUT: fn @F() {
  245. // CHECK:STDOUT: !entry:
  246. // CHECK:STDOUT: %Modifiers.ref: <namespace> = name_ref Modifiers, imports.%Modifiers [template = imports.%Modifiers]
  247. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%import_ref.1 [template = constants.%Base]
  248. // CHECK:STDOUT: %v.var: ref %Base = var v
  249. // CHECK:STDOUT: %v: ref %Base = bind_name v, %v.var
  250. // CHECK:STDOUT: %.loc7_28.1: %.5 = struct_literal ()
  251. // CHECK:STDOUT: %.loc7_28.2: init %Base = class_init (<error>), %v.var [template = <error>]
  252. // CHECK:STDOUT: %.loc7_29: init %Base = converted %.loc7_28.1, %.loc7_28.2 [template = <error>]
  253. // CHECK:STDOUT: assign %v.var, %.loc7_29
  254. // CHECK:STDOUT: return
  255. // CHECK:STDOUT: }
  256. // CHECK:STDOUT:
  257. // CHECK:STDOUT: --- impl_abstract.carbon
  258. // CHECK:STDOUT:
  259. // CHECK:STDOUT: constants {
  260. // CHECK:STDOUT: %A1: type = class_type @A1 [template]
  261. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  262. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  263. // CHECK:STDOUT: %.1: type = ptr_type <vtable> [template]
  264. // CHECK:STDOUT: %.2: type = struct_type {.<vptr>: %.1} [template]
  265. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  266. // CHECK:STDOUT: %A2: type = class_type @A2 [template]
  267. // CHECK:STDOUT: %.5: type = unbound_element_type %A2, %A1 [template]
  268. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  269. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  270. // CHECK:STDOUT: %.6: type = struct_type {.base: %A1} [template]
  271. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT:
  274. // CHECK:STDOUT: imports {
  275. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  276. // CHECK:STDOUT: import Core//prelude
  277. // CHECK:STDOUT: import Core//prelude/...
  278. // CHECK:STDOUT: }
  279. // CHECK:STDOUT: }
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: file {
  282. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  283. // CHECK:STDOUT: .Core = imports.%Core
  284. // CHECK:STDOUT: .A1 = %A1.decl
  285. // CHECK:STDOUT: .A2 = %A2.decl
  286. // CHECK:STDOUT: }
  287. // CHECK:STDOUT: %Core.import = import Core
  288. // CHECK:STDOUT: %A1.decl: type = class_decl @A1 [template = constants.%A1] {} {}
  289. // CHECK:STDOUT: %A2.decl: type = class_decl @A2 [template = constants.%A2] {} {}
  290. // CHECK:STDOUT: }
  291. // CHECK:STDOUT:
  292. // CHECK:STDOUT: class @A1 {
  293. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  294. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.2 [template = constants.%.3]
  295. // CHECK:STDOUT:
  296. // CHECK:STDOUT: !members:
  297. // CHECK:STDOUT: .Self = constants.%A1
  298. // CHECK:STDOUT: .F = %F.decl
  299. // CHECK:STDOUT: }
  300. // CHECK:STDOUT:
  301. // CHECK:STDOUT: class @A2 {
  302. // CHECK:STDOUT: %A1.ref: type = name_ref A1, file.%A1.decl [template = constants.%A1]
  303. // CHECK:STDOUT: %.loc9: %.5 = base_decl %A1.ref, element0 [template]
  304. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {}
  305. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %.6 [template = constants.%.7]
  306. // CHECK:STDOUT:
  307. // CHECK:STDOUT: !members:
  308. // CHECK:STDOUT: .Self = constants.%A2
  309. // CHECK:STDOUT: .base = %.loc9
  310. // CHECK:STDOUT: .F = %F.decl
  311. // CHECK:STDOUT: extend %A1.ref
  312. // CHECK:STDOUT: }
  313. // CHECK:STDOUT:
  314. // CHECK:STDOUT: virtual fn @F.1();
  315. // CHECK:STDOUT:
  316. // CHECK:STDOUT: impl fn @F.2();
  317. // CHECK:STDOUT:
  318. // CHECK:STDOUT: --- impl_base.carbon
  319. // CHECK:STDOUT:
  320. // CHECK:STDOUT: constants {
  321. // CHECK:STDOUT: %B1: type = class_type @B1 [template]
  322. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  323. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  324. // CHECK:STDOUT: %.1: type = ptr_type <vtable> [template]
  325. // CHECK:STDOUT: %.2: type = struct_type {.<vptr>: %.1} [template]
  326. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  327. // CHECK:STDOUT: %B2: type = class_type @B2 [template]
  328. // CHECK:STDOUT: %.5: type = unbound_element_type %B2, %B1 [template]
  329. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  330. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  331. // CHECK:STDOUT: %.6: type = struct_type {.base: %B1} [template]
  332. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  333. // CHECK:STDOUT: %C: type = class_type @C [template]
  334. // CHECK:STDOUT: %.10: type = unbound_element_type %C, %B2 [template]
  335. // CHECK:STDOUT: %F.type.3: type = fn_type @F.3 [template]
  336. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  337. // CHECK:STDOUT: %.11: type = struct_type {.base: %B2} [template]
  338. // CHECK:STDOUT: %.12: <witness> = complete_type_witness %.11 [template]
  339. // CHECK:STDOUT: }
  340. // CHECK:STDOUT:
  341. // CHECK:STDOUT: imports {
  342. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  343. // CHECK:STDOUT: import Core//prelude
  344. // CHECK:STDOUT: import Core//prelude/...
  345. // CHECK:STDOUT: }
  346. // CHECK:STDOUT: }
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: file {
  349. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  350. // CHECK:STDOUT: .Core = imports.%Core
  351. // CHECK:STDOUT: .B1 = %B1.decl
  352. // CHECK:STDOUT: .B2 = %B2.decl
  353. // CHECK:STDOUT: .C = %C.decl
  354. // CHECK:STDOUT: }
  355. // CHECK:STDOUT: %Core.import = import Core
  356. // CHECK:STDOUT: %B1.decl: type = class_decl @B1 [template = constants.%B1] {} {}
  357. // CHECK:STDOUT: %B2.decl: type = class_decl @B2 [template = constants.%B2] {} {}
  358. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  359. // CHECK:STDOUT: }
  360. // CHECK:STDOUT:
  361. // CHECK:STDOUT: class @B1 {
  362. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  363. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.2 [template = constants.%.3]
  364. // CHECK:STDOUT:
  365. // CHECK:STDOUT: !members:
  366. // CHECK:STDOUT: .Self = constants.%B1
  367. // CHECK:STDOUT: .F = %F.decl
  368. // CHECK:STDOUT: }
  369. // CHECK:STDOUT:
  370. // CHECK:STDOUT: class @B2 {
  371. // CHECK:STDOUT: %B1.ref: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  372. // CHECK:STDOUT: %.loc9: %.5 = base_decl %B1.ref, element0 [template]
  373. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {}
  374. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %.6 [template = constants.%.7]
  375. // CHECK:STDOUT:
  376. // CHECK:STDOUT: !members:
  377. // CHECK:STDOUT: .Self = constants.%B2
  378. // CHECK:STDOUT: .base = %.loc9
  379. // CHECK:STDOUT: .F = %F.decl
  380. // CHECK:STDOUT: extend %B1.ref
  381. // CHECK:STDOUT: }
  382. // CHECK:STDOUT:
  383. // CHECK:STDOUT: class @C {
  384. // CHECK:STDOUT: %B2.ref: type = name_ref B2, file.%B2.decl [template = constants.%B2]
  385. // CHECK:STDOUT: %.loc14: %.10 = base_decl %B2.ref, element0 [template]
  386. // CHECK:STDOUT: %F.decl: %F.type.3 = fn_decl @F.3 [template = constants.%F.3] {} {}
  387. // CHECK:STDOUT: %.loc16: <witness> = complete_type_witness %.11 [template = constants.%.12]
  388. // CHECK:STDOUT:
  389. // CHECK:STDOUT: !members:
  390. // CHECK:STDOUT: .Self = constants.%C
  391. // CHECK:STDOUT: .base = %.loc14
  392. // CHECK:STDOUT: .F = %F.decl
  393. // CHECK:STDOUT: extend %B2.ref
  394. // CHECK:STDOUT: }
  395. // CHECK:STDOUT:
  396. // CHECK:STDOUT: virtual fn @F.1();
  397. // CHECK:STDOUT:
  398. // CHECK:STDOUT: impl fn @F.2();
  399. // CHECK:STDOUT:
  400. // CHECK:STDOUT: impl fn @F.3();
  401. // CHECK:STDOUT:
  402. // CHECK:STDOUT: --- fail_modifiers.carbon
  403. // CHECK:STDOUT:
  404. // CHECK:STDOUT: constants {
  405. // CHECK:STDOUT: %C: type = class_type @C [template]
  406. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  407. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  408. // CHECK:STDOUT: %.1: type = ptr_type <vtable> [template]
  409. // CHECK:STDOUT: %.2: type = struct_type {.<vptr>: %.1} [template]
  410. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  411. // CHECK:STDOUT: }
  412. // CHECK:STDOUT:
  413. // CHECK:STDOUT: imports {
  414. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  415. // CHECK:STDOUT: import Core//prelude
  416. // CHECK:STDOUT: import Core//prelude/...
  417. // CHECK:STDOUT: }
  418. // CHECK:STDOUT: }
  419. // CHECK:STDOUT:
  420. // CHECK:STDOUT: file {
  421. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  422. // CHECK:STDOUT: .Core = imports.%Core
  423. // CHECK:STDOUT: .C = %C.decl
  424. // CHECK:STDOUT: }
  425. // CHECK:STDOUT: %Core.import = import Core
  426. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  427. // CHECK:STDOUT: }
  428. // CHECK:STDOUT:
  429. // CHECK:STDOUT: class @C {
  430. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  431. // CHECK:STDOUT: %.loc9: <witness> = complete_type_witness %.2 [template = constants.%.3]
  432. // CHECK:STDOUT:
  433. // CHECK:STDOUT: !members:
  434. // CHECK:STDOUT: .Self = constants.%C
  435. // CHECK:STDOUT: .F = %F.decl
  436. // CHECK:STDOUT: }
  437. // CHECK:STDOUT:
  438. // CHECK:STDOUT: impl fn @F();
  439. // CHECK:STDOUT:
  440. // CHECK:STDOUT: --- init_members.carbon
  441. // CHECK:STDOUT:
  442. // CHECK:STDOUT: constants {
  443. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  444. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  445. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  446. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  447. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  448. // CHECK:STDOUT: %.2: type = unbound_element_type %Base, %i32 [template]
  449. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  450. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  451. // CHECK:STDOUT: %.3: type = ptr_type <vtable> [template]
  452. // CHECK:STDOUT: %.4: type = struct_type {.<vptr>: %.3, .m1: %i32, .m2: %i32} [template]
  453. // CHECK:STDOUT: %.5: <witness> = complete_type_witness %.4 [template]
  454. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  455. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  456. // CHECK:STDOUT: %.6: Core.IntLiteral = int_value 3 [template]
  457. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  458. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  459. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  460. // CHECK:STDOUT: %.30: <witness> = interface_witness (%Convert.14) [template]
  461. // CHECK:STDOUT: %.31: <bound method> = bound_method %.6, %Convert.14 [template]
  462. // CHECK:STDOUT: %.32: <specific function> = specific_function %.31, @Convert.2(%.1) [template]
  463. // CHECK:STDOUT: %.33: %i32 = int_value 3 [template]
  464. // CHECK:STDOUT: %.35: type = struct_type {.m2: %i32, .m1: %i32} [template]
  465. // CHECK:STDOUT: %.36: Core.IntLiteral = int_value 5 [template]
  466. // CHECK:STDOUT: %.37: type = struct_type {.m2: Core.IntLiteral, .m1: Core.IntLiteral} [template]
  467. // CHECK:STDOUT: %.38: <bound method> = bound_method %.36, %Convert.14 [template]
  468. // CHECK:STDOUT: %.39: <specific function> = specific_function %.38, @Convert.2(%.1) [template]
  469. // CHECK:STDOUT: %.40: %i32 = int_value 5 [template]
  470. // CHECK:STDOUT: %.41: Core.IntLiteral = int_value 4 [template]
  471. // CHECK:STDOUT: %.42: <bound method> = bound_method %.41, %Convert.14 [template]
  472. // CHECK:STDOUT: %.43: <specific function> = specific_function %.42, @Convert.2(%.1) [template]
  473. // CHECK:STDOUT: %.44: %i32 = int_value 4 [template]
  474. // CHECK:STDOUT: }
  475. // CHECK:STDOUT:
  476. // CHECK:STDOUT: imports {
  477. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  478. // CHECK:STDOUT: .Int = %import_ref.1
  479. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  480. // CHECK:STDOUT: import Core//prelude
  481. // CHECK:STDOUT: import Core//prelude/...
  482. // CHECK:STDOUT: }
  483. // CHECK:STDOUT: }
  484. // CHECK:STDOUT:
  485. // CHECK:STDOUT: file {
  486. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  487. // CHECK:STDOUT: .Core = imports.%Core
  488. // CHECK:STDOUT: .Base = %Base.decl
  489. // CHECK:STDOUT: .F = %F.decl
  490. // CHECK:STDOUT: }
  491. // CHECK:STDOUT: %Core.import = import Core
  492. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {} {}
  493. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {}
  494. // CHECK:STDOUT: }
  495. // CHECK:STDOUT:
  496. // CHECK:STDOUT: class @Base {
  497. // CHECK:STDOUT: %.loc5_11.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  498. // CHECK:STDOUT: %int.make_type_signed.loc5: init type = call constants.%Int(%.loc5_11.1) [template = constants.%i32]
  499. // CHECK:STDOUT: %.loc5_11.2: type = value_of_initializer %int.make_type_signed.loc5 [template = constants.%i32]
  500. // CHECK:STDOUT: %.loc5_11.3: type = converted %int.make_type_signed.loc5, %.loc5_11.2 [template = constants.%i32]
  501. // CHECK:STDOUT: %.loc5_9: %.2 = field_decl m1, element1 [template]
  502. // CHECK:STDOUT: %.loc6_11.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  503. // CHECK:STDOUT: %int.make_type_signed.loc6: init type = call constants.%Int(%.loc6_11.1) [template = constants.%i32]
  504. // CHECK:STDOUT: %.loc6_11.2: type = value_of_initializer %int.make_type_signed.loc6 [template = constants.%i32]
  505. // CHECK:STDOUT: %.loc6_11.3: type = converted %int.make_type_signed.loc6, %.loc6_11.2 [template = constants.%i32]
  506. // CHECK:STDOUT: %.loc6_9: %.2 = field_decl m2, element2 [template]
  507. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  508. // CHECK:STDOUT: %.loc9: <witness> = complete_type_witness %.4 [template = constants.%.5]
  509. // CHECK:STDOUT:
  510. // CHECK:STDOUT: !members:
  511. // CHECK:STDOUT: .Self = constants.%Base
  512. // CHECK:STDOUT: .m1 = %.loc5_9
  513. // CHECK:STDOUT: .m2 = %.loc6_9
  514. // CHECK:STDOUT: .F = %F.decl
  515. // CHECK:STDOUT: }
  516. // CHECK:STDOUT:
  517. // CHECK:STDOUT: virtual fn @F.1();
  518. // CHECK:STDOUT:
  519. // CHECK:STDOUT: fn @F.2() {
  520. // CHECK:STDOUT: !entry:
  521. // CHECK:STDOUT: %.loc12_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  522. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc12_10.1) [template = constants.%i32]
  523. // CHECK:STDOUT: %.loc12_10.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  524. // CHECK:STDOUT: %.loc12_10.3: type = converted %int.make_type_signed, %.loc12_10.2 [template = constants.%i32]
  525. // CHECK:STDOUT: %i.var: ref %i32 = var i
  526. // CHECK:STDOUT: %i: ref %i32 = bind_name i, %i.var
  527. // CHECK:STDOUT: %.loc12_16: Core.IntLiteral = int_value 3 [template = constants.%.6]
  528. // CHECK:STDOUT: %.loc12_17.1: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  529. // CHECK:STDOUT: %.loc12_17.2: <bound method> = bound_method %.loc12_16, %.loc12_17.1 [template = constants.%.31]
  530. // CHECK:STDOUT: %.loc12_17.3: <specific function> = specific_function %.loc12_17.2, @Convert.2(constants.%.1) [template = constants.%.32]
  531. // CHECK:STDOUT: %int.convert_checked.loc12: init %i32 = call %.loc12_17.3(%.loc12_16) [template = constants.%.33]
  532. // CHECK:STDOUT: %.loc12_17.4: init %i32 = converted %.loc12_16, %int.convert_checked.loc12 [template = constants.%.33]
  533. // CHECK:STDOUT: assign %i.var, %.loc12_17.4
  534. // CHECK:STDOUT: %Base.ref.loc14: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  535. // CHECK:STDOUT: %b1.var: ref %Base = var b1
  536. // CHECK:STDOUT: %b1: ref %Base = bind_name b1, %b1.var
  537. // CHECK:STDOUT: %i.ref.loc14_25: ref %i32 = name_ref i, %i
  538. // CHECK:STDOUT: %i.ref.loc14_34: ref %i32 = name_ref i, %i
  539. // CHECK:STDOUT: %.loc14_35.1: %.35 = struct_literal (%i.ref.loc14_25, %i.ref.loc14_34)
  540. // CHECK:STDOUT: %.loc14_34: %i32 = bind_value %i.ref.loc14_34
  541. // CHECK:STDOUT: %.loc14_35.2: ref %i32 = class_element_access %b1.var, element2
  542. // CHECK:STDOUT: %.loc14_35.3: init %i32 = initialize_from %.loc14_34 to %.loc14_35.2
  543. // CHECK:STDOUT: %.loc14_25: %i32 = bind_value %i.ref.loc14_25
  544. // CHECK:STDOUT: %.loc14_35.4: ref %i32 = class_element_access %b1.var, element1
  545. // CHECK:STDOUT: %.loc14_35.5: init %i32 = initialize_from %.loc14_25 to %.loc14_35.4
  546. // CHECK:STDOUT: %.loc14_35.6: init %Base = class_init (<error>, %.loc14_35.3, %.loc14_35.5), %b1.var
  547. // CHECK:STDOUT: %.loc14_36: init %Base = converted %.loc14_35.1, %.loc14_35.6
  548. // CHECK:STDOUT: assign %b1.var, %.loc14_36
  549. // CHECK:STDOUT: %Base.ref.loc15: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  550. // CHECK:STDOUT: %b2.var: ref %Base = var b2
  551. // CHECK:STDOUT: %b2: ref %Base = bind_name b2, %b2.var
  552. // CHECK:STDOUT: %.loc15_25: Core.IntLiteral = int_value 3 [template = constants.%.6]
  553. // CHECK:STDOUT: %.loc15_34: Core.IntLiteral = int_value 5 [template = constants.%.36]
  554. // CHECK:STDOUT: %.loc15_35.1: %.37 = struct_literal (%.loc15_25, %.loc15_34)
  555. // CHECK:STDOUT: %.loc15_35.2: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  556. // CHECK:STDOUT: %.loc15_35.3: <bound method> = bound_method %.loc15_34, %.loc15_35.2 [template = constants.%.38]
  557. // CHECK:STDOUT: %.loc15_35.4: <specific function> = specific_function %.loc15_35.3, @Convert.2(constants.%.1) [template = constants.%.39]
  558. // CHECK:STDOUT: %int.convert_checked.loc15_35.1: init %i32 = call %.loc15_35.4(%.loc15_34) [template = constants.%.40]
  559. // CHECK:STDOUT: %.loc15_35.5: init %i32 = converted %.loc15_34, %int.convert_checked.loc15_35.1 [template = constants.%.40]
  560. // CHECK:STDOUT: %.loc15_35.6: ref %i32 = class_element_access %b2.var, element2
  561. // CHECK:STDOUT: %.loc15_35.7: init %i32 = initialize_from %.loc15_35.5 to %.loc15_35.6 [template = constants.%.40]
  562. // CHECK:STDOUT: %.loc15_35.8: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  563. // CHECK:STDOUT: %.loc15_35.9: <bound method> = bound_method %.loc15_25, %.loc15_35.8 [template = constants.%.31]
  564. // CHECK:STDOUT: %.loc15_35.10: <specific function> = specific_function %.loc15_35.9, @Convert.2(constants.%.1) [template = constants.%.32]
  565. // CHECK:STDOUT: %int.convert_checked.loc15_35.2: init %i32 = call %.loc15_35.10(%.loc15_25) [template = constants.%.33]
  566. // CHECK:STDOUT: %.loc15_35.11: init %i32 = converted %.loc15_25, %int.convert_checked.loc15_35.2 [template = constants.%.33]
  567. // CHECK:STDOUT: %.loc15_35.12: ref %i32 = class_element_access %b2.var, element1
  568. // CHECK:STDOUT: %.loc15_35.13: init %i32 = initialize_from %.loc15_35.11 to %.loc15_35.12 [template = constants.%.33]
  569. // CHECK:STDOUT: %.loc15_35.14: init %Base = class_init (<error>, %.loc15_35.7, %.loc15_35.13), %b2.var [template = <error>]
  570. // CHECK:STDOUT: %.loc15_36: init %Base = converted %.loc15_35.1, %.loc15_35.14 [template = <error>]
  571. // CHECK:STDOUT: assign %b2.var, %.loc15_36
  572. // CHECK:STDOUT: %b1.ref: ref %Base = name_ref b1, %b1
  573. // CHECK:STDOUT: %m2.ref: %.2 = name_ref m2, @Base.%.loc6_9 [template = @Base.%.loc6_9]
  574. // CHECK:STDOUT: %.loc18_5: ref %i32 = class_element_access %b1.ref, element2
  575. // CHECK:STDOUT: %.loc18_11: Core.IntLiteral = int_value 4 [template = constants.%.41]
  576. // CHECK:STDOUT: %.loc18_9.1: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.14]
  577. // CHECK:STDOUT: %.loc18_9.2: <bound method> = bound_method %.loc18_11, %.loc18_9.1 [template = constants.%.42]
  578. // CHECK:STDOUT: %.loc18_9.3: <specific function> = specific_function %.loc18_9.2, @Convert.2(constants.%.1) [template = constants.%.43]
  579. // CHECK:STDOUT: %int.convert_checked.loc18: init %i32 = call %.loc18_9.3(%.loc18_11) [template = constants.%.44]
  580. // CHECK:STDOUT: %.loc18_9.4: init %i32 = converted %.loc18_11, %int.convert_checked.loc18 [template = constants.%.44]
  581. // CHECK:STDOUT: assign %.loc18_5, %.loc18_9.4
  582. // CHECK:STDOUT: return
  583. // CHECK:STDOUT: }
  584. // CHECK:STDOUT:
  585. // CHECK:STDOUT: --- todo_fail_impl_without_base_declaration.carbon
  586. // CHECK:STDOUT:
  587. // CHECK:STDOUT: constants {
  588. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  589. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  590. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  591. // CHECK:STDOUT: %Derived: type = class_type @Derived [template]
  592. // CHECK:STDOUT: %.4: type = unbound_element_type %Derived, %Base [template]
  593. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  594. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  595. // CHECK:STDOUT: %.5: type = ptr_type <vtable> [template]
  596. // CHECK:STDOUT: %.6: type = struct_type {.<vptr>: %.5, .base: %Base} [template]
  597. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  598. // CHECK:STDOUT: }
  599. // CHECK:STDOUT:
  600. // CHECK:STDOUT: imports {
  601. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  602. // CHECK:STDOUT: import Core//prelude
  603. // CHECK:STDOUT: import Core//prelude/...
  604. // CHECK:STDOUT: }
  605. // CHECK:STDOUT: }
  606. // CHECK:STDOUT:
  607. // CHECK:STDOUT: file {
  608. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  609. // CHECK:STDOUT: .Core = imports.%Core
  610. // CHECK:STDOUT: .Base = %Base.decl
  611. // CHECK:STDOUT: .Derived = %Derived.decl
  612. // CHECK:STDOUT: }
  613. // CHECK:STDOUT: %Core.import = import Core
  614. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {} {}
  615. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [template = constants.%Derived] {} {}
  616. // CHECK:STDOUT: }
  617. // CHECK:STDOUT:
  618. // CHECK:STDOUT: class @Base {
  619. // CHECK:STDOUT: %.loc5: <witness> = complete_type_witness %.1 [template = constants.%.2]
  620. // CHECK:STDOUT:
  621. // CHECK:STDOUT: !members:
  622. // CHECK:STDOUT: .Self = constants.%Base
  623. // CHECK:STDOUT: }
  624. // CHECK:STDOUT:
  625. // CHECK:STDOUT: class @Derived {
  626. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  627. // CHECK:STDOUT: %.loc8: %.4 = base_decl %Base.ref, element1 [template]
  628. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  629. // CHECK:STDOUT: %.loc10: <witness> = complete_type_witness %.6 [template = constants.%.7]
  630. // CHECK:STDOUT:
  631. // CHECK:STDOUT: !members:
  632. // CHECK:STDOUT: .Self = constants.%Derived
  633. // CHECK:STDOUT: .base = %.loc8
  634. // CHECK:STDOUT: .F = %F.decl
  635. // CHECK:STDOUT: extend %Base.ref
  636. // CHECK:STDOUT: }
  637. // CHECK:STDOUT:
  638. // CHECK:STDOUT: impl fn @F();
  639. // CHECK:STDOUT: