inheritance_access.carbon 64 KB

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