inheritance_access.carbon 58 KB

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