inheritance_access.carbon 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  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/inheritance_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/inheritance_access.carbon
  10. // --- instance_protected_field_access.carbon
  11. library "[[@TEST_NAME]]";
  12. base class Shape {
  13. protected var x: i32;
  14. protected var y: i32;
  15. }
  16. class Circle {
  17. extend base: Shape;
  18. fn GetPosition[self: Self]() -> (i32, i32) {
  19. return (self.x, self.y);
  20. }
  21. }
  22. // --- shadowing_access.carbon
  23. library "[[@TEST_NAME]]";
  24. base class A {
  25. fn F();
  26. }
  27. base class B {
  28. extend base: A;
  29. private fn F() -> i32;
  30. }
  31. base class C {
  32. extend base: B;
  33. fn G[self: Self]() -> () { return self.F(); }
  34. }
  35. // --- inherited_member_access.carbon
  36. library "[[@TEST_NAME]]";
  37. base class A {
  38. protected let SOME_CONSTANT: i32 = 5;
  39. protected fn SomeProtectedFunction() -> i32 {
  40. return 5;
  41. }
  42. }
  43. class B {
  44. extend base: A;
  45. fn G() -> i32 {
  46. return A.SOME_CONSTANT;
  47. }
  48. fn H() -> i32 {
  49. return A.SomeProtectedFunction();
  50. }
  51. }
  52. // --- fail_inherited_private_field_access.carbon
  53. library "[[@TEST_NAME]]";
  54. base class Shape {
  55. private var y: i32;
  56. }
  57. class Square {
  58. extend base: Shape;
  59. fn GetPosition[self: Self]() -> i32 {
  60. // CHECK:STDERR: fail_inherited_private_field_access.carbon:[[@LINE+7]]:12: error: cannot access private member `y` of type `Shape` [ClassInvalidMemberAccess]
  61. // CHECK:STDERR: return self.y;
  62. // CHECK:STDERR: ^~~~~~
  63. // CHECK:STDERR: fail_inherited_private_field_access.carbon:[[@LINE-10]]:15: note: declared here [ClassMemberDeclaration]
  64. // CHECK:STDERR: private var y: i32;
  65. // CHECK:STDERR: ^~~~~~
  66. // CHECK:STDERR:
  67. return self.y;
  68. }
  69. }
  70. // --- noninstance_private_on_self.carbon
  71. library "[[@TEST_NAME]]";
  72. class C {
  73. private fn F() {}
  74. fn G() { Self.F(); }
  75. }
  76. // --- noninstance_protected_on_self.carbon
  77. library "[[@TEST_NAME]]";
  78. class C {
  79. protected fn F() {}
  80. fn G() { Self.F(); }
  81. }
  82. // --- fail_noninstance_private_on_parent.carbon
  83. library "[[@TEST_NAME]]";
  84. base class B {
  85. private fn F() {}
  86. }
  87. class C {
  88. extend base: B;
  89. // CHECK:STDERR: fail_noninstance_private_on_parent.carbon:[[@LINE+7]]:12: error: cannot access private member `F` of type `B` [ClassInvalidMemberAccess]
  90. // CHECK:STDERR: fn G() { Self.F(); }
  91. // CHECK:STDERR: ^~~~~~
  92. // CHECK:STDERR: fail_noninstance_private_on_parent.carbon:[[@LINE-8]]:3: note: declared here [ClassMemberDeclaration]
  93. // CHECK:STDERR: private fn F() {}
  94. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  95. // CHECK:STDERR:
  96. fn G() { Self.F(); }
  97. }
  98. // --- noninstance_protected_on_parent.carbon
  99. library "[[@TEST_NAME]]";
  100. base class B {
  101. protected fn F() {}
  102. }
  103. class C {
  104. extend base: B;
  105. fn G() { Self.F(); }
  106. }
  107. // --- fail_non_inherited_access.carbon
  108. library "[[@TEST_NAME]]";
  109. base class A {
  110. protected let SOME_PROTECTED_CONSTANT: i32 = 5;
  111. private let SOME_PRIVATE_CONSTANT: i32 = 5;
  112. }
  113. base class Internal {
  114. protected let INTERNAL_CONSTANT: i32 = 5;
  115. }
  116. class B {
  117. private var internal: Internal;
  118. fn G() -> i32 {
  119. // CHECK:STDERR: fail_non_inherited_access.carbon:[[@LINE+7]]:5: error: cannot access private member `SOME_PRIVATE_CONSTANT` of type `A` [ClassInvalidMemberAccess]
  120. // CHECK:STDERR: A.SOME_PRIVATE_CONSTANT;
  121. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
  122. // CHECK:STDERR: fail_non_inherited_access.carbon:[[@LINE-14]]:15: note: declared here [ClassMemberDeclaration]
  123. // CHECK:STDERR: private let SOME_PRIVATE_CONSTANT: i32 = 5;
  124. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  125. // CHECK:STDERR:
  126. A.SOME_PRIVATE_CONSTANT;
  127. // CHECK:STDERR: fail_non_inherited_access.carbon:[[@LINE+7]]:12: error: cannot access protected member `SOME_PROTECTED_CONSTANT` of type `A` [ClassInvalidMemberAccess]
  128. // CHECK:STDERR: return A.SOME_PROTECTED_CONSTANT;
  129. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  130. // CHECK:STDERR: fail_non_inherited_access.carbon:[[@LINE-24]]:17: note: declared here [ClassMemberDeclaration]
  131. // CHECK:STDERR: protected let SOME_PROTECTED_CONSTANT: i32 = 5;
  132. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
  133. // CHECK:STDERR:
  134. return A.SOME_PROTECTED_CONSTANT;
  135. }
  136. fn SomeFunc[self: Self]() -> i32{
  137. // CHECK:STDERR: fail_non_inherited_access.carbon:[[@LINE+7]]:12: error: cannot access protected member `INTERNAL_CONSTANT` of type `Internal` [ClassInvalidMemberAccess]
  138. // CHECK:STDERR: return self.internal.INTERNAL_CONSTANT;
  139. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140. // CHECK:STDERR: fail_non_inherited_access.carbon:[[@LINE-30]]:17: note: declared here [ClassMemberDeclaration]
  141. // CHECK:STDERR: protected let INTERNAL_CONSTANT: i32 = 5;
  142. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  143. // CHECK:STDERR:
  144. return self.internal.INTERNAL_CONSTANT;
  145. }
  146. }
  147. // --- fail_compound_member_access.carbon
  148. library "[[@TEST_NAME]]";
  149. base class A {
  150. private var x: i32;
  151. }
  152. class B {
  153. extend base: A;
  154. fn F[self: Self]() {
  155. // CHECK:STDERR: fail_compound_member_access.carbon:[[@LINE+6]]:11: error: cannot access private member `x` of type `A` [ClassInvalidMemberAccess]
  156. // CHECK:STDERR: self.(A.x);
  157. // CHECK:STDERR: ^~~
  158. // CHECK:STDERR: fail_compound_member_access.carbon:[[@LINE-9]]:15: note: declared here [ClassMemberDeclaration]
  159. // CHECK:STDERR: private var x: i32;
  160. // CHECK:STDERR: ^~~~~~
  161. self.(A.x);
  162. }
  163. }
  164. // --- inherited_compound_member_access.carbon
  165. library "[[@TEST_NAME]]";
  166. base class A {
  167. protected var x: i32;
  168. }
  169. class B {
  170. extend base: A;
  171. fn F[self: Self]() {
  172. self.(A.x);
  173. }
  174. }
  175. // CHECK:STDOUT: --- instance_protected_field_access.carbon
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: constants {
  178. // CHECK:STDOUT: %Shape: type = class_type @Shape [template]
  179. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  180. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  181. // CHECK:STDOUT: %.1: type = unbound_element_type %Shape, i32 [template]
  182. // CHECK:STDOUT: %.2: type = struct_type {.x: i32, .y: i32} [template]
  183. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  184. // CHECK:STDOUT: %Circle: type = class_type @Circle [template]
  185. // CHECK:STDOUT: %.5: type = unbound_element_type %Circle, %Shape [template]
  186. // CHECK:STDOUT: %tuple.type.1: type = tuple_type (type, type) [template]
  187. // CHECK:STDOUT: %tuple.type.2: type = tuple_type (i32, i32) [template]
  188. // CHECK:STDOUT: %GetPosition.type: type = fn_type @GetPosition [template]
  189. // CHECK:STDOUT: %GetPosition: %GetPosition.type = struct_value () [template]
  190. // CHECK:STDOUT: %.6: type = struct_type {.base: %Shape} [template]
  191. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: imports {
  195. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  196. // CHECK:STDOUT: .Int32 = %import_ref
  197. // CHECK:STDOUT: import Core//prelude
  198. // CHECK:STDOUT: import Core//prelude/...
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: file {
  203. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  204. // CHECK:STDOUT: .Core = imports.%Core
  205. // CHECK:STDOUT: .Shape = %Shape.decl
  206. // CHECK:STDOUT: .Circle = %Circle.decl
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT: %Core.import = import Core
  209. // CHECK:STDOUT: %Shape.decl: type = class_decl @Shape [template = constants.%Shape] {} {}
  210. // CHECK:STDOUT: %Circle.decl: type = class_decl @Circle [template = constants.%Circle] {} {}
  211. // CHECK:STDOUT: }
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: class @Shape {
  214. // CHECK:STDOUT: %int.make_type_32.loc5: init type = call constants.%Int32() [template = i32]
  215. // CHECK:STDOUT: %.loc5_20.1: type = value_of_initializer %int.make_type_32.loc5 [template = i32]
  216. // CHECK:STDOUT: %.loc5_20.2: type = converted %int.make_type_32.loc5, %.loc5_20.1 [template = i32]
  217. // CHECK:STDOUT: %.loc5_18: %.1 = field_decl x, element0 [template]
  218. // CHECK:STDOUT: %int.make_type_32.loc6: init type = call constants.%Int32() [template = i32]
  219. // CHECK:STDOUT: %.loc6_20.1: type = value_of_initializer %int.make_type_32.loc6 [template = i32]
  220. // CHECK:STDOUT: %.loc6_20.2: type = converted %int.make_type_32.loc6, %.loc6_20.1 [template = i32]
  221. // CHECK:STDOUT: %.loc6_18: %.1 = field_decl y, element1 [template]
  222. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.2 [template = constants.%.3]
  223. // CHECK:STDOUT:
  224. // CHECK:STDOUT: !members:
  225. // CHECK:STDOUT: .Self = constants.%Shape
  226. // CHECK:STDOUT: .x [protected] = %.loc5_18
  227. // CHECK:STDOUT: .y [protected] = %.loc6_18
  228. // CHECK:STDOUT: }
  229. // CHECK:STDOUT:
  230. // CHECK:STDOUT: class @Circle {
  231. // CHECK:STDOUT: %Shape.ref: type = name_ref Shape, file.%Shape.decl [template = constants.%Shape]
  232. // CHECK:STDOUT: %.loc10: %.5 = base_decl %Shape, element0 [template]
  233. // CHECK:STDOUT: %GetPosition.decl: %GetPosition.type = fn_decl @GetPosition [template = constants.%GetPosition] {
  234. // CHECK:STDOUT: %self.patt: %Circle = binding_pattern self
  235. // CHECK:STDOUT: %self.param_patt: %Circle = value_param_pattern %self.patt, runtime_param0
  236. // CHECK:STDOUT: %return.patt: %tuple.type.2 = return_slot_pattern
  237. // CHECK:STDOUT: %return.param_patt: %tuple.type.2 = out_param_pattern %return.patt, runtime_param1
  238. // CHECK:STDOUT: } {
  239. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Circle [template = constants.%Circle]
  240. // CHECK:STDOUT: %int.make_type_32.loc12_36: init type = call constants.%Int32() [template = i32]
  241. // CHECK:STDOUT: %int.make_type_32.loc12_41: init type = call constants.%Int32() [template = i32]
  242. // CHECK:STDOUT: %.loc12_44.1: %tuple.type.1 = tuple_literal (%int.make_type_32.loc12_36, %int.make_type_32.loc12_41)
  243. // CHECK:STDOUT: %.loc12_44.2: type = value_of_initializer %int.make_type_32.loc12_36 [template = i32]
  244. // CHECK:STDOUT: %.loc12_44.3: type = converted %int.make_type_32.loc12_36, %.loc12_44.2 [template = i32]
  245. // CHECK:STDOUT: %.loc12_44.4: type = value_of_initializer %int.make_type_32.loc12_41 [template = i32]
  246. // CHECK:STDOUT: %.loc12_44.5: type = converted %int.make_type_32.loc12_41, %.loc12_44.4 [template = i32]
  247. // CHECK:STDOUT: %.loc12_44.6: type = converted %.loc12_44.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  248. // CHECK:STDOUT: %self.param: %Circle = value_param runtime_param0
  249. // CHECK:STDOUT: %self: %Circle = bind_name self, %self.param
  250. // CHECK:STDOUT: %return.param: ref %tuple.type.2 = out_param runtime_param1
  251. // CHECK:STDOUT: %return: ref %tuple.type.2 = return_slot %return.param
  252. // CHECK:STDOUT: }
  253. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.6 [template = constants.%.7]
  254. // CHECK:STDOUT:
  255. // CHECK:STDOUT: !members:
  256. // CHECK:STDOUT: .Self = constants.%Circle
  257. // CHECK:STDOUT: .base = %.loc10
  258. // CHECK:STDOUT: .GetPosition = %GetPosition.decl
  259. // CHECK:STDOUT: extend %Shape.ref
  260. // CHECK:STDOUT: }
  261. // CHECK:STDOUT:
  262. // CHECK:STDOUT: fn @GetPosition[%self.param_patt: %Circle]() -> %return: %tuple.type.2 {
  263. // CHECK:STDOUT: !entry:
  264. // CHECK:STDOUT: %self.ref.loc13_13: %Circle = name_ref self, %self
  265. // CHECK:STDOUT: %x.ref: %.1 = name_ref x, @Shape.%.loc5_18 [template = @Shape.%.loc5_18]
  266. // CHECK:STDOUT: %.loc13_17.1: ref %Shape = class_element_access %self.ref.loc13_13, element0
  267. // CHECK:STDOUT: %.loc13_17.2: ref %Shape = converted %self.ref.loc13_13, %.loc13_17.1
  268. // CHECK:STDOUT: %.loc13_17.3: ref i32 = class_element_access %.loc13_17.2, element0
  269. // CHECK:STDOUT: %self.ref.loc13_21: %Circle = name_ref self, %self
  270. // CHECK:STDOUT: %y.ref: %.1 = name_ref y, @Shape.%.loc6_18 [template = @Shape.%.loc6_18]
  271. // CHECK:STDOUT: %.loc13_25.1: ref %Shape = class_element_access %self.ref.loc13_21, element0
  272. // CHECK:STDOUT: %.loc13_25.2: ref %Shape = converted %self.ref.loc13_21, %.loc13_25.1
  273. // CHECK:STDOUT: %.loc13_25.3: ref i32 = class_element_access %.loc13_25.2, element1
  274. // CHECK:STDOUT: %.loc13_27.1: %tuple.type.2 = tuple_literal (%.loc13_17.3, %.loc13_25.3)
  275. // CHECK:STDOUT: %.loc13_17.4: i32 = bind_value %.loc13_17.3
  276. // CHECK:STDOUT: %.loc13_27.2: ref i32 = tuple_access %return, element0
  277. // CHECK:STDOUT: %.loc13_27.3: init i32 = initialize_from %.loc13_17.4 to %.loc13_27.2
  278. // CHECK:STDOUT: %.loc13_25.4: i32 = bind_value %.loc13_25.3
  279. // CHECK:STDOUT: %.loc13_27.4: ref i32 = tuple_access %return, element1
  280. // CHECK:STDOUT: %.loc13_27.5: init i32 = initialize_from %.loc13_25.4 to %.loc13_27.4
  281. // CHECK:STDOUT: %.loc13_27.6: init %tuple.type.2 = tuple_init (%.loc13_27.3, %.loc13_27.5) to %return
  282. // CHECK:STDOUT: %.loc13_28: init %tuple.type.2 = converted %.loc13_27.1, %.loc13_27.6
  283. // CHECK:STDOUT: return %.loc13_28 to %return
  284. // CHECK:STDOUT: }
  285. // CHECK:STDOUT:
  286. // CHECK:STDOUT: --- shadowing_access.carbon
  287. // CHECK:STDOUT:
  288. // CHECK:STDOUT: constants {
  289. // CHECK:STDOUT: %A: type = class_type @A [template]
  290. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  291. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  292. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  293. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  294. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  295. // CHECK:STDOUT: %B: type = class_type @B [template]
  296. // CHECK:STDOUT: %.4: type = unbound_element_type %B, %A [template]
  297. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  298. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  299. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  300. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  301. // CHECK:STDOUT: %.5: type = struct_type {.base: %A} [template]
  302. // CHECK:STDOUT: %.6: <witness> = complete_type_witness %.5 [template]
  303. // CHECK:STDOUT: %C: type = class_type @C [template]
  304. // CHECK:STDOUT: %.9: type = unbound_element_type %C, %B [template]
  305. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  306. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  307. // CHECK:STDOUT: %.10: type = struct_type {.base: %B} [template]
  308. // CHECK:STDOUT: %.11: <witness> = complete_type_witness %.10 [template]
  309. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [template]
  310. // CHECK:STDOUT: }
  311. // CHECK:STDOUT:
  312. // CHECK:STDOUT: imports {
  313. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  314. // CHECK:STDOUT: .Int32 = %import_ref
  315. // CHECK:STDOUT: import Core//prelude
  316. // CHECK:STDOUT: import Core//prelude/...
  317. // CHECK:STDOUT: }
  318. // CHECK:STDOUT: }
  319. // CHECK:STDOUT:
  320. // CHECK:STDOUT: file {
  321. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  322. // CHECK:STDOUT: .Core = imports.%Core
  323. // CHECK:STDOUT: .A = %A.decl
  324. // CHECK:STDOUT: .B = %B.decl
  325. // CHECK:STDOUT: .C = %C.decl
  326. // CHECK:STDOUT: }
  327. // CHECK:STDOUT: %Core.import = import Core
  328. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  329. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  330. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  331. // CHECK:STDOUT: }
  332. // CHECK:STDOUT:
  333. // CHECK:STDOUT: class @A {
  334. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  335. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.1 [template = constants.%.2]
  336. // CHECK:STDOUT:
  337. // CHECK:STDOUT: !members:
  338. // CHECK:STDOUT: .Self = constants.%A
  339. // CHECK:STDOUT: .F = %F.decl
  340. // CHECK:STDOUT: }
  341. // CHECK:STDOUT:
  342. // CHECK:STDOUT: class @B {
  343. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  344. // CHECK:STDOUT: %.loc9: %.4 = base_decl %A, element0 [template]
  345. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {
  346. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  347. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param0
  348. // CHECK:STDOUT: } {
  349. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  350. // CHECK:STDOUT: %.loc10_21.1: type = value_of_initializer %int.make_type_32 [template = i32]
  351. // CHECK:STDOUT: %.loc10_21.2: type = converted %int.make_type_32, %.loc10_21.1 [template = i32]
  352. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param0
  353. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  354. // CHECK:STDOUT: }
  355. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %.5 [template = constants.%.6]
  356. // CHECK:STDOUT:
  357. // CHECK:STDOUT: !members:
  358. // CHECK:STDOUT: .Self = constants.%B
  359. // CHECK:STDOUT: .base = %.loc9
  360. // CHECK:STDOUT: .F [private] = %F.decl
  361. // CHECK:STDOUT: extend %A.ref
  362. // CHECK:STDOUT: }
  363. // CHECK:STDOUT:
  364. // CHECK:STDOUT: class @C {
  365. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  366. // CHECK:STDOUT: %.loc14: %.9 = base_decl %B, element0 [template]
  367. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  368. // CHECK:STDOUT: %self.patt: %C = binding_pattern self
  369. // CHECK:STDOUT: %self.param_patt: %C = value_param_pattern %self.patt, runtime_param0
  370. // CHECK:STDOUT: %return.patt: %empty_tuple.type = return_slot_pattern
  371. // CHECK:STDOUT: %return.param_patt: %empty_tuple.type = out_param_pattern %return.patt, runtime_param1
  372. // CHECK:STDOUT: } {
  373. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  374. // CHECK:STDOUT: %.loc15_26.1: %empty_tuple.type = tuple_literal ()
  375. // CHECK:STDOUT: %.loc15_26.2: type = converted %.loc15_26.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  376. // CHECK:STDOUT: %self.param: %C = value_param runtime_param0
  377. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  378. // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param runtime_param1
  379. // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
  380. // CHECK:STDOUT: }
  381. // CHECK:STDOUT: %.loc16: <witness> = complete_type_witness %.10 [template = constants.%.11]
  382. // CHECK:STDOUT:
  383. // CHECK:STDOUT: !members:
  384. // CHECK:STDOUT: .Self = constants.%C
  385. // CHECK:STDOUT: .base = %.loc14
  386. // CHECK:STDOUT: .G = %G.decl
  387. // CHECK:STDOUT: extend %B.ref
  388. // CHECK:STDOUT: }
  389. // CHECK:STDOUT:
  390. // CHECK:STDOUT: fn @F.1();
  391. // CHECK:STDOUT:
  392. // CHECK:STDOUT: fn @F.2() -> i32;
  393. // CHECK:STDOUT:
  394. // CHECK:STDOUT: fn @G[%self.param_patt: %C]() -> %empty_tuple.type {
  395. // CHECK:STDOUT: !entry:
  396. // CHECK:STDOUT: %self.ref: %C = name_ref self, %self
  397. // CHECK:STDOUT: %F.ref: %F.type.1 = name_ref F, @A.%F.decl [template = constants.%F.1]
  398. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  399. // CHECK:STDOUT: %.loc15_43.1: ref %empty_tuple.type = temporary_storage
  400. // CHECK:STDOUT: %.loc15_43.2: ref %empty_tuple.type = temporary %.loc15_43.1, %F.call
  401. // CHECK:STDOUT: %tuple: %empty_tuple.type = tuple_value () [template = constants.%empty_tuple]
  402. // CHECK:STDOUT: %.loc15_45: %empty_tuple.type = converted %F.call, %tuple [template = constants.%empty_tuple]
  403. // CHECK:STDOUT: return %.loc15_45
  404. // CHECK:STDOUT: }
  405. // CHECK:STDOUT:
  406. // CHECK:STDOUT: --- inherited_member_access.carbon
  407. // CHECK:STDOUT:
  408. // CHECK:STDOUT: constants {
  409. // CHECK:STDOUT: %A: type = class_type @A [template]
  410. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  411. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  412. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 5 [template]
  413. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(i32) [template]
  414. // CHECK:STDOUT: %Convert.type.15: type = fn_type @Convert.11 [template]
  415. // CHECK:STDOUT: %Convert.15: %Convert.type.15 = struct_value () [template]
  416. // CHECK:STDOUT: %.25: <witness> = interface_witness (%Convert.15) [template]
  417. // CHECK:STDOUT: %.26: <bound method> = bound_method %.1, %Convert.15 [template]
  418. // CHECK:STDOUT: %.27: i32 = int_value 5 [template]
  419. // CHECK:STDOUT: %SomeProtectedFunction.type: type = fn_type @SomeProtectedFunction [template]
  420. // CHECK:STDOUT: %SomeProtectedFunction: %SomeProtectedFunction.type = struct_value () [template]
  421. // CHECK:STDOUT: %.28: type = struct_type {} [template]
  422. // CHECK:STDOUT: %.29: <witness> = complete_type_witness %.28 [template]
  423. // CHECK:STDOUT: %B: type = class_type @B [template]
  424. // CHECK:STDOUT: %.31: type = unbound_element_type %B, %A [template]
  425. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  426. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  427. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  428. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  429. // CHECK:STDOUT: %.32: type = struct_type {.base: %A} [template]
  430. // CHECK:STDOUT: %.33: <witness> = complete_type_witness %.32 [template]
  431. // CHECK:STDOUT: }
  432. // CHECK:STDOUT:
  433. // CHECK:STDOUT: imports {
  434. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  435. // CHECK:STDOUT: .Int32 = %import_ref.1
  436. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  437. // CHECK:STDOUT: import Core//prelude
  438. // CHECK:STDOUT: import Core//prelude/...
  439. // CHECK:STDOUT: }
  440. // CHECK:STDOUT: }
  441. // CHECK:STDOUT:
  442. // CHECK:STDOUT: file {
  443. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  444. // CHECK:STDOUT: .Core = imports.%Core
  445. // CHECK:STDOUT: .A = %A.decl
  446. // CHECK:STDOUT: .B = %B.decl
  447. // CHECK:STDOUT: }
  448. // CHECK:STDOUT: %Core.import = import Core
  449. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  450. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  451. // CHECK:STDOUT: }
  452. // CHECK:STDOUT:
  453. // CHECK:STDOUT: class @A {
  454. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  455. // CHECK:STDOUT: %.loc5_32.1: type = value_of_initializer %int.make_type_32 [template = i32]
  456. // CHECK:STDOUT: %.loc5_32.2: type = converted %int.make_type_32, %.loc5_32.1 [template = i32]
  457. // CHECK:STDOUT: %.loc5_38: Core.IntLiteral = int_value 5 [template = constants.%.1]
  458. // CHECK:STDOUT: %.loc5_39.1: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.15]
  459. // CHECK:STDOUT: %.loc5_39.2: <bound method> = bound_method %.loc5_38, %.loc5_39.1 [template = constants.%.26]
  460. // CHECK:STDOUT: %int.convert_checked: init i32 = call %.loc5_39.2(%.loc5_38) [template = constants.%.27]
  461. // CHECK:STDOUT: %.loc5_39.3: i32 = value_of_initializer %int.convert_checked [template = constants.%.27]
  462. // CHECK:STDOUT: %.loc5_39.4: i32 = converted %.loc5_38, %.loc5_39.3 [template = constants.%.27]
  463. // CHECK:STDOUT: %SOME_CONSTANT: i32 = bind_name SOME_CONSTANT, %.loc5_39.4
  464. // CHECK:STDOUT: %SomeProtectedFunction.decl: %SomeProtectedFunction.type = fn_decl @SomeProtectedFunction [template = constants.%SomeProtectedFunction] {
  465. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  466. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param0
  467. // CHECK:STDOUT: } {
  468. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  469. // CHECK:STDOUT: %.loc6_43.1: type = value_of_initializer %int.make_type_32 [template = i32]
  470. // CHECK:STDOUT: %.loc6_43.2: type = converted %int.make_type_32, %.loc6_43.1 [template = i32]
  471. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param0
  472. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  473. // CHECK:STDOUT: }
  474. // CHECK:STDOUT: %.loc9: <witness> = complete_type_witness %.28 [template = constants.%.29]
  475. // CHECK:STDOUT:
  476. // CHECK:STDOUT: !members:
  477. // CHECK:STDOUT: .Self = constants.%A
  478. // CHECK:STDOUT: .SOME_CONSTANT [protected] = %SOME_CONSTANT
  479. // CHECK:STDOUT: .SomeProtectedFunction [protected] = %SomeProtectedFunction.decl
  480. // CHECK:STDOUT: }
  481. // CHECK:STDOUT:
  482. // CHECK:STDOUT: class @B {
  483. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  484. // CHECK:STDOUT: %.loc12: %.31 = base_decl %A, element0 [template]
  485. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  486. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  487. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param0
  488. // CHECK:STDOUT: } {
  489. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  490. // CHECK:STDOUT: %.loc14_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  491. // CHECK:STDOUT: %.loc14_13.2: type = converted %int.make_type_32, %.loc14_13.1 [template = i32]
  492. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param0
  493. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  494. // CHECK:STDOUT: }
  495. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {
  496. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  497. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param0
  498. // CHECK:STDOUT: } {
  499. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  500. // CHECK:STDOUT: %.loc18_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  501. // CHECK:STDOUT: %.loc18_13.2: type = converted %int.make_type_32, %.loc18_13.1 [template = i32]
  502. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param0
  503. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  504. // CHECK:STDOUT: }
  505. // CHECK:STDOUT: %.loc21: <witness> = complete_type_witness %.32 [template = constants.%.33]
  506. // CHECK:STDOUT:
  507. // CHECK:STDOUT: !members:
  508. // CHECK:STDOUT: .Self = constants.%B
  509. // CHECK:STDOUT: .base = %.loc12
  510. // CHECK:STDOUT: .G = %G.decl
  511. // CHECK:STDOUT: .H = %H.decl
  512. // CHECK:STDOUT: extend %A.ref
  513. // CHECK:STDOUT: }
  514. // CHECK:STDOUT:
  515. // CHECK:STDOUT: fn @SomeProtectedFunction() -> i32 {
  516. // CHECK:STDOUT: !entry:
  517. // CHECK:STDOUT: %.loc7_12: Core.IntLiteral = int_value 5 [template = constants.%.1]
  518. // CHECK:STDOUT: %.loc7_13.1: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.15]
  519. // CHECK:STDOUT: %.loc7_13.2: <bound method> = bound_method %.loc7_12, %.loc7_13.1 [template = constants.%.26]
  520. // CHECK:STDOUT: %int.convert_checked: init i32 = call %.loc7_13.2(%.loc7_12) [template = constants.%.27]
  521. // CHECK:STDOUT: %.loc7_13.3: i32 = value_of_initializer %int.convert_checked [template = constants.%.27]
  522. // CHECK:STDOUT: %.loc7_13.4: i32 = converted %.loc7_12, %.loc7_13.3 [template = constants.%.27]
  523. // CHECK:STDOUT: return %.loc7_13.4
  524. // CHECK:STDOUT: }
  525. // CHECK:STDOUT:
  526. // CHECK:STDOUT: fn @G() -> i32 {
  527. // CHECK:STDOUT: !entry:
  528. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  529. // CHECK:STDOUT: %SOME_CONSTANT.ref: i32 = name_ref SOME_CONSTANT, @A.%SOME_CONSTANT
  530. // CHECK:STDOUT: return %SOME_CONSTANT.ref
  531. // CHECK:STDOUT: }
  532. // CHECK:STDOUT:
  533. // CHECK:STDOUT: fn @H() -> i32 {
  534. // CHECK:STDOUT: !entry:
  535. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  536. // CHECK:STDOUT: %SomeProtectedFunction.ref: %SomeProtectedFunction.type = name_ref SomeProtectedFunction, @A.%SomeProtectedFunction.decl [template = constants.%SomeProtectedFunction]
  537. // CHECK:STDOUT: %SomeProtectedFunction.call: init i32 = call %SomeProtectedFunction.ref()
  538. // CHECK:STDOUT: %.loc19_37.1: i32 = value_of_initializer %SomeProtectedFunction.call
  539. // CHECK:STDOUT: %.loc19_37.2: i32 = converted %SomeProtectedFunction.call, %.loc19_37.1
  540. // CHECK:STDOUT: return %.loc19_37.2
  541. // CHECK:STDOUT: }
  542. // CHECK:STDOUT:
  543. // CHECK:STDOUT: --- fail_inherited_private_field_access.carbon
  544. // CHECK:STDOUT:
  545. // CHECK:STDOUT: constants {
  546. // CHECK:STDOUT: %Shape: type = class_type @Shape [template]
  547. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  548. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  549. // CHECK:STDOUT: %.1: type = unbound_element_type %Shape, i32 [template]
  550. // CHECK:STDOUT: %.2: type = struct_type {.y: i32} [template]
  551. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  552. // CHECK:STDOUT: %Square: type = class_type @Square [template]
  553. // CHECK:STDOUT: %.5: type = unbound_element_type %Square, %Shape [template]
  554. // CHECK:STDOUT: %GetPosition.type: type = fn_type @GetPosition [template]
  555. // CHECK:STDOUT: %GetPosition: %GetPosition.type = struct_value () [template]
  556. // CHECK:STDOUT: %.6: type = struct_type {.base: %Shape} [template]
  557. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  558. // CHECK:STDOUT: }
  559. // CHECK:STDOUT:
  560. // CHECK:STDOUT: imports {
  561. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  562. // CHECK:STDOUT: .Int32 = %import_ref
  563. // CHECK:STDOUT: import Core//prelude
  564. // CHECK:STDOUT: import Core//prelude/...
  565. // CHECK:STDOUT: }
  566. // CHECK:STDOUT: }
  567. // CHECK:STDOUT:
  568. // CHECK:STDOUT: file {
  569. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  570. // CHECK:STDOUT: .Core = imports.%Core
  571. // CHECK:STDOUT: .Shape = %Shape.decl
  572. // CHECK:STDOUT: .Square = %Square.decl
  573. // CHECK:STDOUT: }
  574. // CHECK:STDOUT: %Core.import = import Core
  575. // CHECK:STDOUT: %Shape.decl: type = class_decl @Shape [template = constants.%Shape] {} {}
  576. // CHECK:STDOUT: %Square.decl: type = class_decl @Square [template = constants.%Square] {} {}
  577. // CHECK:STDOUT: }
  578. // CHECK:STDOUT:
  579. // CHECK:STDOUT: class @Shape {
  580. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  581. // CHECK:STDOUT: %.loc5_18.1: type = value_of_initializer %int.make_type_32 [template = i32]
  582. // CHECK:STDOUT: %.loc5_18.2: type = converted %int.make_type_32, %.loc5_18.1 [template = i32]
  583. // CHECK:STDOUT: %.loc5_16: %.1 = field_decl y, element0 [template]
  584. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.2 [template = constants.%.3]
  585. // CHECK:STDOUT:
  586. // CHECK:STDOUT: !members:
  587. // CHECK:STDOUT: .Self = constants.%Shape
  588. // CHECK:STDOUT: .y [private] = %.loc5_16
  589. // CHECK:STDOUT: }
  590. // CHECK:STDOUT:
  591. // CHECK:STDOUT: class @Square {
  592. // CHECK:STDOUT: %Shape.ref: type = name_ref Shape, file.%Shape.decl [template = constants.%Shape]
  593. // CHECK:STDOUT: %.loc9: %.5 = base_decl %Shape, element0 [template]
  594. // CHECK:STDOUT: %GetPosition.decl: %GetPosition.type = fn_decl @GetPosition [template = constants.%GetPosition] {
  595. // CHECK:STDOUT: %self.patt: %Square = binding_pattern self
  596. // CHECK:STDOUT: %self.param_patt: %Square = value_param_pattern %self.patt, runtime_param0
  597. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  598. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param1
  599. // CHECK:STDOUT: } {
  600. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Square [template = constants.%Square]
  601. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  602. // CHECK:STDOUT: %.loc11_35.1: type = value_of_initializer %int.make_type_32 [template = i32]
  603. // CHECK:STDOUT: %.loc11_35.2: type = converted %int.make_type_32, %.loc11_35.1 [template = i32]
  604. // CHECK:STDOUT: %self.param: %Square = value_param runtime_param0
  605. // CHECK:STDOUT: %self: %Square = bind_name self, %self.param
  606. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param1
  607. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  608. // CHECK:STDOUT: }
  609. // CHECK:STDOUT: %.loc21: <witness> = complete_type_witness %.6 [template = constants.%.7]
  610. // CHECK:STDOUT:
  611. // CHECK:STDOUT: !members:
  612. // CHECK:STDOUT: .Self = constants.%Square
  613. // CHECK:STDOUT: .base = %.loc9
  614. // CHECK:STDOUT: .GetPosition = %GetPosition.decl
  615. // CHECK:STDOUT: extend %Shape.ref
  616. // CHECK:STDOUT: }
  617. // CHECK:STDOUT:
  618. // CHECK:STDOUT: fn @GetPosition[%self.param_patt: %Square]() -> i32 {
  619. // CHECK:STDOUT: !entry:
  620. // CHECK:STDOUT: %self.ref: %Square = name_ref self, %self
  621. // CHECK:STDOUT: %y.ref: <error> = name_ref y, <error> [template = <error>]
  622. // CHECK:STDOUT: return <error>
  623. // CHECK:STDOUT: }
  624. // CHECK:STDOUT:
  625. // CHECK:STDOUT: --- noninstance_private_on_self.carbon
  626. // CHECK:STDOUT:
  627. // CHECK:STDOUT: constants {
  628. // CHECK:STDOUT: %C: type = class_type @C [template]
  629. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  630. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  631. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  632. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  633. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  634. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  635. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  636. // CHECK:STDOUT: }
  637. // CHECK:STDOUT:
  638. // CHECK:STDOUT: imports {
  639. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  640. // CHECK:STDOUT: import Core//prelude
  641. // CHECK:STDOUT: import Core//prelude/...
  642. // CHECK:STDOUT: }
  643. // CHECK:STDOUT: }
  644. // CHECK:STDOUT:
  645. // CHECK:STDOUT: file {
  646. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  647. // CHECK:STDOUT: .Core = imports.%Core
  648. // CHECK:STDOUT: .C = %C.decl
  649. // CHECK:STDOUT: }
  650. // CHECK:STDOUT: %Core.import = import Core
  651. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  652. // CHECK:STDOUT: }
  653. // CHECK:STDOUT:
  654. // CHECK:STDOUT: class @C {
  655. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  656. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  657. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.1 [template = constants.%.2]
  658. // CHECK:STDOUT:
  659. // CHECK:STDOUT: !members:
  660. // CHECK:STDOUT: .Self = constants.%C
  661. // CHECK:STDOUT: .F [private] = %F.decl
  662. // CHECK:STDOUT: .G = %G.decl
  663. // CHECK:STDOUT: }
  664. // CHECK:STDOUT:
  665. // CHECK:STDOUT: fn @F() {
  666. // CHECK:STDOUT: !entry:
  667. // CHECK:STDOUT: return
  668. // CHECK:STDOUT: }
  669. // CHECK:STDOUT:
  670. // CHECK:STDOUT: fn @G() {
  671. // CHECK:STDOUT: !entry:
  672. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  673. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @C.%F.decl [template = constants.%F]
  674. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  675. // CHECK:STDOUT: return
  676. // CHECK:STDOUT: }
  677. // CHECK:STDOUT:
  678. // CHECK:STDOUT: --- noninstance_protected_on_self.carbon
  679. // CHECK:STDOUT:
  680. // CHECK:STDOUT: constants {
  681. // CHECK:STDOUT: %C: type = class_type @C [template]
  682. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  683. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  684. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  685. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  686. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  687. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  688. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  689. // CHECK:STDOUT: }
  690. // CHECK:STDOUT:
  691. // CHECK:STDOUT: imports {
  692. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  693. // CHECK:STDOUT: import Core//prelude
  694. // CHECK:STDOUT: import Core//prelude/...
  695. // CHECK:STDOUT: }
  696. // CHECK:STDOUT: }
  697. // CHECK:STDOUT:
  698. // CHECK:STDOUT: file {
  699. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  700. // CHECK:STDOUT: .Core = imports.%Core
  701. // CHECK:STDOUT: .C = %C.decl
  702. // CHECK:STDOUT: }
  703. // CHECK:STDOUT: %Core.import = import Core
  704. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  705. // CHECK:STDOUT: }
  706. // CHECK:STDOUT:
  707. // CHECK:STDOUT: class @C {
  708. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  709. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  710. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.1 [template = constants.%.2]
  711. // CHECK:STDOUT:
  712. // CHECK:STDOUT: !members:
  713. // CHECK:STDOUT: .Self = constants.%C
  714. // CHECK:STDOUT: .F [protected] = %F.decl
  715. // CHECK:STDOUT: .G = %G.decl
  716. // CHECK:STDOUT: }
  717. // CHECK:STDOUT:
  718. // CHECK:STDOUT: fn @F() {
  719. // CHECK:STDOUT: !entry:
  720. // CHECK:STDOUT: return
  721. // CHECK:STDOUT: }
  722. // CHECK:STDOUT:
  723. // CHECK:STDOUT: fn @G() {
  724. // CHECK:STDOUT: !entry:
  725. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  726. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @C.%F.decl [template = constants.%F]
  727. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  728. // CHECK:STDOUT: return
  729. // CHECK:STDOUT: }
  730. // CHECK:STDOUT:
  731. // CHECK:STDOUT: --- fail_noninstance_private_on_parent.carbon
  732. // CHECK:STDOUT:
  733. // CHECK:STDOUT: constants {
  734. // CHECK:STDOUT: %B: type = class_type @B [template]
  735. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  736. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  737. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  738. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  739. // CHECK:STDOUT: %C: type = class_type @C [template]
  740. // CHECK:STDOUT: %.4: type = unbound_element_type %C, %B [template]
  741. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  742. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  743. // CHECK:STDOUT: %.5: type = struct_type {.base: %B} [template]
  744. // CHECK:STDOUT: %.6: <witness> = complete_type_witness %.5 [template]
  745. // CHECK:STDOUT: }
  746. // CHECK:STDOUT:
  747. // CHECK:STDOUT: imports {
  748. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  749. // CHECK:STDOUT: import Core//prelude
  750. // CHECK:STDOUT: import Core//prelude/...
  751. // CHECK:STDOUT: }
  752. // CHECK:STDOUT: }
  753. // CHECK:STDOUT:
  754. // CHECK:STDOUT: file {
  755. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  756. // CHECK:STDOUT: .Core = imports.%Core
  757. // CHECK:STDOUT: .B = %B.decl
  758. // CHECK:STDOUT: .C = %C.decl
  759. // CHECK:STDOUT: }
  760. // CHECK:STDOUT: %Core.import = import Core
  761. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  762. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  763. // CHECK:STDOUT: }
  764. // CHECK:STDOUT:
  765. // CHECK:STDOUT: class @B {
  766. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  767. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.1 [template = constants.%.2]
  768. // CHECK:STDOUT:
  769. // CHECK:STDOUT: !members:
  770. // CHECK:STDOUT: .Self = constants.%B
  771. // CHECK:STDOUT: .F [private] = %F.decl
  772. // CHECK:STDOUT: }
  773. // CHECK:STDOUT:
  774. // CHECK:STDOUT: class @C {
  775. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  776. // CHECK:STDOUT: %.loc9: %.4 = base_decl %B, element0 [template]
  777. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  778. // CHECK:STDOUT: %.loc18: <witness> = complete_type_witness %.5 [template = constants.%.6]
  779. // CHECK:STDOUT:
  780. // CHECK:STDOUT: !members:
  781. // CHECK:STDOUT: .Self = constants.%C
  782. // CHECK:STDOUT: .base = %.loc9
  783. // CHECK:STDOUT: .G = %G.decl
  784. // CHECK:STDOUT: extend %B.ref
  785. // CHECK:STDOUT: }
  786. // CHECK:STDOUT:
  787. // CHECK:STDOUT: fn @F() {
  788. // CHECK:STDOUT: !entry:
  789. // CHECK:STDOUT: return
  790. // CHECK:STDOUT: }
  791. // CHECK:STDOUT:
  792. // CHECK:STDOUT: fn @G() {
  793. // CHECK:STDOUT: !entry:
  794. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  795. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
  796. // CHECK:STDOUT: return
  797. // CHECK:STDOUT: }
  798. // CHECK:STDOUT:
  799. // CHECK:STDOUT: --- noninstance_protected_on_parent.carbon
  800. // CHECK:STDOUT:
  801. // CHECK:STDOUT: constants {
  802. // CHECK:STDOUT: %B: type = class_type @B [template]
  803. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  804. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  805. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  806. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  807. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  808. // CHECK:STDOUT: %C: type = class_type @C [template]
  809. // CHECK:STDOUT: %.4: type = unbound_element_type %C, %B [template]
  810. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  811. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  812. // CHECK:STDOUT: %.5: type = struct_type {.base: %B} [template]
  813. // CHECK:STDOUT: %.6: <witness> = complete_type_witness %.5 [template]
  814. // CHECK:STDOUT: }
  815. // CHECK:STDOUT:
  816. // CHECK:STDOUT: imports {
  817. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  818. // CHECK:STDOUT: import Core//prelude
  819. // CHECK:STDOUT: import Core//prelude/...
  820. // CHECK:STDOUT: }
  821. // CHECK:STDOUT: }
  822. // CHECK:STDOUT:
  823. // CHECK:STDOUT: file {
  824. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  825. // CHECK:STDOUT: .Core = imports.%Core
  826. // CHECK:STDOUT: .B = %B.decl
  827. // CHECK:STDOUT: .C = %C.decl
  828. // CHECK:STDOUT: }
  829. // CHECK:STDOUT: %Core.import = import Core
  830. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  831. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  832. // CHECK:STDOUT: }
  833. // CHECK:STDOUT:
  834. // CHECK:STDOUT: class @B {
  835. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  836. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.1 [template = constants.%.2]
  837. // CHECK:STDOUT:
  838. // CHECK:STDOUT: !members:
  839. // CHECK:STDOUT: .Self = constants.%B
  840. // CHECK:STDOUT: .F [protected] = %F.decl
  841. // CHECK:STDOUT: }
  842. // CHECK:STDOUT:
  843. // CHECK:STDOUT: class @C {
  844. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  845. // CHECK:STDOUT: %.loc9: %.4 = base_decl %B, element0 [template]
  846. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  847. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %.5 [template = constants.%.6]
  848. // CHECK:STDOUT:
  849. // CHECK:STDOUT: !members:
  850. // CHECK:STDOUT: .Self = constants.%C
  851. // CHECK:STDOUT: .base = %.loc9
  852. // CHECK:STDOUT: .G = %G.decl
  853. // CHECK:STDOUT: extend %B.ref
  854. // CHECK:STDOUT: }
  855. // CHECK:STDOUT:
  856. // CHECK:STDOUT: fn @F() {
  857. // CHECK:STDOUT: !entry:
  858. // CHECK:STDOUT: return
  859. // CHECK:STDOUT: }
  860. // CHECK:STDOUT:
  861. // CHECK:STDOUT: fn @G() {
  862. // CHECK:STDOUT: !entry:
  863. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  864. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @B.%F.decl [template = constants.%F]
  865. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  866. // CHECK:STDOUT: return
  867. // CHECK:STDOUT: }
  868. // CHECK:STDOUT:
  869. // CHECK:STDOUT: --- fail_non_inherited_access.carbon
  870. // CHECK:STDOUT:
  871. // CHECK:STDOUT: constants {
  872. // CHECK:STDOUT: %A: type = class_type @A [template]
  873. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  874. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  875. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 5 [template]
  876. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(i32) [template]
  877. // CHECK:STDOUT: %Convert.type.15: type = fn_type @Convert.11 [template]
  878. // CHECK:STDOUT: %Convert.15: %Convert.type.15 = struct_value () [template]
  879. // CHECK:STDOUT: %.25: <witness> = interface_witness (%Convert.15) [template]
  880. // CHECK:STDOUT: %.26: <bound method> = bound_method %.1, %Convert.15 [template]
  881. // CHECK:STDOUT: %.27: i32 = int_value 5 [template]
  882. // CHECK:STDOUT: %.28: type = struct_type {} [template]
  883. // CHECK:STDOUT: %.29: <witness> = complete_type_witness %.28 [template]
  884. // CHECK:STDOUT: %Internal: type = class_type @Internal [template]
  885. // CHECK:STDOUT: %B: type = class_type @B [template]
  886. // CHECK:STDOUT: %.31: type = unbound_element_type %B, %Internal [template]
  887. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  888. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  889. // CHECK:STDOUT: %SomeFunc.type: type = fn_type @SomeFunc [template]
  890. // CHECK:STDOUT: %SomeFunc: %SomeFunc.type = struct_value () [template]
  891. // CHECK:STDOUT: %.32: type = struct_type {.internal: %Internal} [template]
  892. // CHECK:STDOUT: %.33: <witness> = complete_type_witness %.32 [template]
  893. // CHECK:STDOUT: }
  894. // CHECK:STDOUT:
  895. // CHECK:STDOUT: imports {
  896. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  897. // CHECK:STDOUT: .Int32 = %import_ref.1
  898. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  899. // CHECK:STDOUT: import Core//prelude
  900. // CHECK:STDOUT: import Core//prelude/...
  901. // CHECK:STDOUT: }
  902. // CHECK:STDOUT: }
  903. // CHECK:STDOUT:
  904. // CHECK:STDOUT: file {
  905. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  906. // CHECK:STDOUT: .Core = imports.%Core
  907. // CHECK:STDOUT: .A = %A.decl
  908. // CHECK:STDOUT: .Internal = %Internal.decl
  909. // CHECK:STDOUT: .B = %B.decl
  910. // CHECK:STDOUT: }
  911. // CHECK:STDOUT: %Core.import = import Core
  912. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  913. // CHECK:STDOUT: %Internal.decl: type = class_decl @Internal [template = constants.%Internal] {} {}
  914. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  915. // CHECK:STDOUT: }
  916. // CHECK:STDOUT:
  917. // CHECK:STDOUT: class @A {
  918. // CHECK:STDOUT: %int.make_type_32.loc5: init type = call constants.%Int32() [template = i32]
  919. // CHECK:STDOUT: %.loc5_42.1: type = value_of_initializer %int.make_type_32.loc5 [template = i32]
  920. // CHECK:STDOUT: %.loc5_42.2: type = converted %int.make_type_32.loc5, %.loc5_42.1 [template = i32]
  921. // CHECK:STDOUT: %.loc5_48: Core.IntLiteral = int_value 5 [template = constants.%.1]
  922. // CHECK:STDOUT: %.loc5_49.1: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.15]
  923. // CHECK:STDOUT: %.loc5_49.2: <bound method> = bound_method %.loc5_48, %.loc5_49.1 [template = constants.%.26]
  924. // CHECK:STDOUT: %int.convert_checked.loc5: init i32 = call %.loc5_49.2(%.loc5_48) [template = constants.%.27]
  925. // CHECK:STDOUT: %.loc5_49.3: i32 = value_of_initializer %int.convert_checked.loc5 [template = constants.%.27]
  926. // CHECK:STDOUT: %.loc5_49.4: i32 = converted %.loc5_48, %.loc5_49.3 [template = constants.%.27]
  927. // CHECK:STDOUT: %SOME_PROTECTED_CONSTANT: i32 = bind_name SOME_PROTECTED_CONSTANT, %.loc5_49.4
  928. // CHECK:STDOUT: %int.make_type_32.loc6: init type = call constants.%Int32() [template = i32]
  929. // CHECK:STDOUT: %.loc6_38.1: type = value_of_initializer %int.make_type_32.loc6 [template = i32]
  930. // CHECK:STDOUT: %.loc6_38.2: type = converted %int.make_type_32.loc6, %.loc6_38.1 [template = i32]
  931. // CHECK:STDOUT: %.loc6_44: Core.IntLiteral = int_value 5 [template = constants.%.1]
  932. // CHECK:STDOUT: %.loc6_45.1: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.15]
  933. // CHECK:STDOUT: %.loc6_45.2: <bound method> = bound_method %.loc6_44, %.loc6_45.1 [template = constants.%.26]
  934. // CHECK:STDOUT: %int.convert_checked.loc6: init i32 = call %.loc6_45.2(%.loc6_44) [template = constants.%.27]
  935. // CHECK:STDOUT: %.loc6_45.3: i32 = value_of_initializer %int.convert_checked.loc6 [template = constants.%.27]
  936. // CHECK:STDOUT: %.loc6_45.4: i32 = converted %.loc6_44, %.loc6_45.3 [template = constants.%.27]
  937. // CHECK:STDOUT: %SOME_PRIVATE_CONSTANT: i32 = bind_name SOME_PRIVATE_CONSTANT, %.loc6_45.4
  938. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.28 [template = constants.%.29]
  939. // CHECK:STDOUT:
  940. // CHECK:STDOUT: !members:
  941. // CHECK:STDOUT: .Self = constants.%A
  942. // CHECK:STDOUT: .SOME_PROTECTED_CONSTANT [protected] = %SOME_PROTECTED_CONSTANT
  943. // CHECK:STDOUT: .SOME_PRIVATE_CONSTANT [private] = %SOME_PRIVATE_CONSTANT
  944. // CHECK:STDOUT: }
  945. // CHECK:STDOUT:
  946. // CHECK:STDOUT: class @Internal {
  947. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  948. // CHECK:STDOUT: %.loc10_36.1: type = value_of_initializer %int.make_type_32 [template = i32]
  949. // CHECK:STDOUT: %.loc10_36.2: type = converted %int.make_type_32, %.loc10_36.1 [template = i32]
  950. // CHECK:STDOUT: %.loc10_42: Core.IntLiteral = int_value 5 [template = constants.%.1]
  951. // CHECK:STDOUT: %.loc10_43.1: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.15]
  952. // CHECK:STDOUT: %.loc10_43.2: <bound method> = bound_method %.loc10_42, %.loc10_43.1 [template = constants.%.26]
  953. // CHECK:STDOUT: %int.convert_checked: init i32 = call %.loc10_43.2(%.loc10_42) [template = constants.%.27]
  954. // CHECK:STDOUT: %.loc10_43.3: i32 = value_of_initializer %int.convert_checked [template = constants.%.27]
  955. // CHECK:STDOUT: %.loc10_43.4: i32 = converted %.loc10_42, %.loc10_43.3 [template = constants.%.27]
  956. // CHECK:STDOUT: %INTERNAL_CONSTANT: i32 = bind_name INTERNAL_CONSTANT, %.loc10_43.4
  957. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %.28 [template = constants.%.29]
  958. // CHECK:STDOUT:
  959. // CHECK:STDOUT: !members:
  960. // CHECK:STDOUT: .Self = constants.%Internal
  961. // CHECK:STDOUT: .INTERNAL_CONSTANT [protected] = %INTERNAL_CONSTANT
  962. // CHECK:STDOUT: }
  963. // CHECK:STDOUT:
  964. // CHECK:STDOUT: class @B {
  965. // CHECK:STDOUT: %Internal.ref: type = name_ref Internal, file.%Internal.decl [template = constants.%Internal]
  966. // CHECK:STDOUT: %.loc14: %.31 = field_decl internal, element0 [template]
  967. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  968. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  969. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param0
  970. // CHECK:STDOUT: } {
  971. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  972. // CHECK:STDOUT: %.loc16_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  973. // CHECK:STDOUT: %.loc16_13.2: type = converted %int.make_type_32, %.loc16_13.1 [template = i32]
  974. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param0
  975. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  976. // CHECK:STDOUT: }
  977. // CHECK:STDOUT: %SomeFunc.decl: %SomeFunc.type = fn_decl @SomeFunc [template = constants.%SomeFunc] {
  978. // CHECK:STDOUT: %self.patt: %B = binding_pattern self
  979. // CHECK:STDOUT: %self.param_patt: %B = value_param_pattern %self.patt, runtime_param0
  980. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  981. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param1
  982. // CHECK:STDOUT: } {
  983. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%B [template = constants.%B]
  984. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  985. // CHECK:STDOUT: %.loc36_32.1: type = value_of_initializer %int.make_type_32 [template = i32]
  986. // CHECK:STDOUT: %.loc36_32.2: type = converted %int.make_type_32, %.loc36_32.1 [template = i32]
  987. // CHECK:STDOUT: %self.param: %B = value_param runtime_param0
  988. // CHECK:STDOUT: %self: %B = bind_name self, %self.param
  989. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param1
  990. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  991. // CHECK:STDOUT: }
  992. // CHECK:STDOUT: %.loc46: <witness> = complete_type_witness %.32 [template = constants.%.33]
  993. // CHECK:STDOUT:
  994. // CHECK:STDOUT: !members:
  995. // CHECK:STDOUT: .Self = constants.%B
  996. // CHECK:STDOUT: .internal [private] = %.loc14
  997. // CHECK:STDOUT: .G = %G.decl
  998. // CHECK:STDOUT: .SomeFunc = %SomeFunc.decl
  999. // CHECK:STDOUT: }
  1000. // CHECK:STDOUT:
  1001. // CHECK:STDOUT: fn @G() -> i32 {
  1002. // CHECK:STDOUT: !entry:
  1003. // CHECK:STDOUT: %A.ref.loc24: type = name_ref A, file.%A.decl [template = constants.%A]
  1004. // CHECK:STDOUT: %SOME_PRIVATE_CONSTANT.ref: <error> = name_ref SOME_PRIVATE_CONSTANT, <error> [template = <error>]
  1005. // CHECK:STDOUT: %A.ref.loc33: type = name_ref A, file.%A.decl [template = constants.%A]
  1006. // CHECK:STDOUT: %SOME_PROTECTED_CONSTANT.ref: <error> = name_ref SOME_PROTECTED_CONSTANT, <error> [template = <error>]
  1007. // CHECK:STDOUT: return <error>
  1008. // CHECK:STDOUT: }
  1009. // CHECK:STDOUT:
  1010. // CHECK:STDOUT: fn @SomeFunc[%self.param_patt: %B]() -> i32 {
  1011. // CHECK:STDOUT: !entry:
  1012. // CHECK:STDOUT: %self.ref: %B = name_ref self, %self
  1013. // CHECK:STDOUT: %internal.ref: %.31 = name_ref internal, @B.%.loc14 [template = @B.%.loc14]
  1014. // CHECK:STDOUT: %.loc44_16.1: ref %Internal = class_element_access %self.ref, element0
  1015. // CHECK:STDOUT: %.loc44_16.2: %Internal = bind_value %.loc44_16.1
  1016. // CHECK:STDOUT: %INTERNAL_CONSTANT.ref: <error> = name_ref INTERNAL_CONSTANT, <error> [template = <error>]
  1017. // CHECK:STDOUT: return <error>
  1018. // CHECK:STDOUT: }
  1019. // CHECK:STDOUT:
  1020. // CHECK:STDOUT: --- fail_compound_member_access.carbon
  1021. // CHECK:STDOUT:
  1022. // CHECK:STDOUT: constants {
  1023. // CHECK:STDOUT: %A: type = class_type @A [template]
  1024. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  1025. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  1026. // CHECK:STDOUT: %.1: type = unbound_element_type %A, i32 [template]
  1027. // CHECK:STDOUT: %.2: type = struct_type {.x: i32} [template]
  1028. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  1029. // CHECK:STDOUT: %B: type = class_type @B [template]
  1030. // CHECK:STDOUT: %.5: type = unbound_element_type %B, %A [template]
  1031. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  1032. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  1033. // CHECK:STDOUT: %.6: type = struct_type {.base: %A} [template]
  1034. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  1035. // CHECK:STDOUT: }
  1036. // CHECK:STDOUT:
  1037. // CHECK:STDOUT: imports {
  1038. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  1039. // CHECK:STDOUT: .Int32 = %import_ref
  1040. // CHECK:STDOUT: import Core//prelude
  1041. // CHECK:STDOUT: import Core//prelude/...
  1042. // CHECK:STDOUT: }
  1043. // CHECK:STDOUT: }
  1044. // CHECK:STDOUT:
  1045. // CHECK:STDOUT: file {
  1046. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  1047. // CHECK:STDOUT: .Core = imports.%Core
  1048. // CHECK:STDOUT: .A = %A.decl
  1049. // CHECK:STDOUT: .B = %B.decl
  1050. // CHECK:STDOUT: }
  1051. // CHECK:STDOUT: %Core.import = import Core
  1052. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  1053. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  1054. // CHECK:STDOUT: }
  1055. // CHECK:STDOUT:
  1056. // CHECK:STDOUT: class @A {
  1057. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  1058. // CHECK:STDOUT: %.loc5_18.1: type = value_of_initializer %int.make_type_32 [template = i32]
  1059. // CHECK:STDOUT: %.loc5_18.2: type = converted %int.make_type_32, %.loc5_18.1 [template = i32]
  1060. // CHECK:STDOUT: %.loc5_16: %.1 = field_decl x, element0 [template]
  1061. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.2 [template = constants.%.3]
  1062. // CHECK:STDOUT:
  1063. // CHECK:STDOUT: !members:
  1064. // CHECK:STDOUT: .Self = constants.%A
  1065. // CHECK:STDOUT: .x [private] = %.loc5_16
  1066. // CHECK:STDOUT: }
  1067. // CHECK:STDOUT:
  1068. // CHECK:STDOUT: class @B {
  1069. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  1070. // CHECK:STDOUT: %.loc9: %.5 = base_decl %A, element0 [template]
  1071. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  1072. // CHECK:STDOUT: %self.patt: %B = binding_pattern self
  1073. // CHECK:STDOUT: %self.param_patt: %B = value_param_pattern %self.patt, runtime_param0
  1074. // CHECK:STDOUT: } {
  1075. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%B [template = constants.%B]
  1076. // CHECK:STDOUT: %self.param: %B = value_param runtime_param0
  1077. // CHECK:STDOUT: %self: %B = bind_name self, %self.param
  1078. // CHECK:STDOUT: }
  1079. // CHECK:STDOUT: %.loc19: <witness> = complete_type_witness %.6 [template = constants.%.7]
  1080. // CHECK:STDOUT:
  1081. // CHECK:STDOUT: !members:
  1082. // CHECK:STDOUT: .Self = constants.%B
  1083. // CHECK:STDOUT: .base = %.loc9
  1084. // CHECK:STDOUT: .F = %F.decl
  1085. // CHECK:STDOUT: extend %A.ref
  1086. // CHECK:STDOUT: }
  1087. // CHECK:STDOUT:
  1088. // CHECK:STDOUT: fn @F[%self.param_patt: %B]() {
  1089. // CHECK:STDOUT: !entry:
  1090. // CHECK:STDOUT: %self.ref: %B = name_ref self, %self
  1091. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  1092. // CHECK:STDOUT: %x.ref: <error> = name_ref x, <error> [template = <error>]
  1093. // CHECK:STDOUT: return
  1094. // CHECK:STDOUT: }
  1095. // CHECK:STDOUT:
  1096. // CHECK:STDOUT: --- inherited_compound_member_access.carbon
  1097. // CHECK:STDOUT:
  1098. // CHECK:STDOUT: constants {
  1099. // CHECK:STDOUT: %A: type = class_type @A [template]
  1100. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  1101. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  1102. // CHECK:STDOUT: %.1: type = unbound_element_type %A, i32 [template]
  1103. // CHECK:STDOUT: %.2: type = struct_type {.x: i32} [template]
  1104. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  1105. // CHECK:STDOUT: %B: type = class_type @B [template]
  1106. // CHECK:STDOUT: %.5: type = unbound_element_type %B, %A [template]
  1107. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  1108. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  1109. // CHECK:STDOUT: %.6: type = struct_type {.base: %A} [template]
  1110. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  1111. // CHECK:STDOUT: }
  1112. // CHECK:STDOUT:
  1113. // CHECK:STDOUT: imports {
  1114. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  1115. // CHECK:STDOUT: .Int32 = %import_ref
  1116. // CHECK:STDOUT: import Core//prelude
  1117. // CHECK:STDOUT: import Core//prelude/...
  1118. // CHECK:STDOUT: }
  1119. // CHECK:STDOUT: }
  1120. // CHECK:STDOUT:
  1121. // CHECK:STDOUT: file {
  1122. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  1123. // CHECK:STDOUT: .Core = imports.%Core
  1124. // CHECK:STDOUT: .A = %A.decl
  1125. // CHECK:STDOUT: .B = %B.decl
  1126. // CHECK:STDOUT: }
  1127. // CHECK:STDOUT: %Core.import = import Core
  1128. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  1129. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  1130. // CHECK:STDOUT: }
  1131. // CHECK:STDOUT:
  1132. // CHECK:STDOUT: class @A {
  1133. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  1134. // CHECK:STDOUT: %.loc5_20.1: type = value_of_initializer %int.make_type_32 [template = i32]
  1135. // CHECK:STDOUT: %.loc5_20.2: type = converted %int.make_type_32, %.loc5_20.1 [template = i32]
  1136. // CHECK:STDOUT: %.loc5_18: %.1 = field_decl x, element0 [template]
  1137. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.2 [template = constants.%.3]
  1138. // CHECK:STDOUT:
  1139. // CHECK:STDOUT: !members:
  1140. // CHECK:STDOUT: .Self = constants.%A
  1141. // CHECK:STDOUT: .x [protected] = %.loc5_18
  1142. // CHECK:STDOUT: }
  1143. // CHECK:STDOUT:
  1144. // CHECK:STDOUT: class @B {
  1145. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  1146. // CHECK:STDOUT: %.loc9: %.5 = base_decl %A, element0 [template]
  1147. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  1148. // CHECK:STDOUT: %self.patt: %B = binding_pattern self
  1149. // CHECK:STDOUT: %self.param_patt: %B = value_param_pattern %self.patt, runtime_param0
  1150. // CHECK:STDOUT: } {
  1151. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%B [template = constants.%B]
  1152. // CHECK:STDOUT: %self.param: %B = value_param runtime_param0
  1153. // CHECK:STDOUT: %self: %B = bind_name self, %self.param
  1154. // CHECK:STDOUT: }
  1155. // CHECK:STDOUT: %.loc14: <witness> = complete_type_witness %.6 [template = constants.%.7]
  1156. // CHECK:STDOUT:
  1157. // CHECK:STDOUT: !members:
  1158. // CHECK:STDOUT: .Self = constants.%B
  1159. // CHECK:STDOUT: .base = %.loc9
  1160. // CHECK:STDOUT: .F = %F.decl
  1161. // CHECK:STDOUT: extend %A.ref
  1162. // CHECK:STDOUT: }
  1163. // CHECK:STDOUT:
  1164. // CHECK:STDOUT: fn @F[%self.param_patt: %B]() {
  1165. // CHECK:STDOUT: !entry:
  1166. // CHECK:STDOUT: %self.ref: %B = name_ref self, %self
  1167. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  1168. // CHECK:STDOUT: %x.ref: %.1 = name_ref x, @A.%.loc5_18 [template = @A.%.loc5_18]
  1169. // CHECK:STDOUT: %.loc12_9.1: ref %A = class_element_access %self.ref, element0
  1170. // CHECK:STDOUT: %.loc12_9.2: ref %A = converted %self.ref, %.loc12_9.1
  1171. // CHECK:STDOUT: %.loc12_9.3: ref i32 = class_element_access %.loc12_9.2, element0
  1172. // CHECK:STDOUT: return
  1173. // CHECK:STDOUT: }
  1174. // CHECK:STDOUT: