inheritance_access.carbon 67 KB

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