inheritance_access.carbon 59 KB

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