access_modifers.carbon 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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/access_modifers.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/access_modifers.carbon
  10. // --- fail_private_field_access.carbon
  11. library "[[@TEST_NAME]]";
  12. class Circle {
  13. private var radius: i32;
  14. private let SOME_INTERNAL_CONSTANT: i32 = 5;
  15. private fn SomeInternalFunction() -> i32 {
  16. return 0;
  17. }
  18. fn Make() -> Self {
  19. return {.radius = 5};
  20. }
  21. }
  22. fn Run() {
  23. let circle: Circle = Circle.Make();
  24. // CHECK:STDERR: fail_private_field_access.carbon:[[@LINE+7]]:21: error: cannot access private member `radius` of type `Circle` [ClassInvalidMemberAccess]
  25. // CHECK:STDERR: let radius: i32 = circle.radius;
  26. // CHECK:STDERR: ^~~~~~~~~~~~~
  27. // CHECK:STDERR: fail_private_field_access.carbon:[[@LINE-17]]:15: note: declared here [ClassMemberDeclaration]
  28. // CHECK:STDERR: private var radius: i32;
  29. // CHECK:STDERR: ^~~~~~~~~~~
  30. // CHECK:STDERR:
  31. let radius: i32 = circle.radius;
  32. // CHECK:STDERR: fail_private_field_access.carbon:[[@LINE+7]]:3: error: cannot access private member `radius` of type `Circle` [ClassInvalidMemberAccess]
  33. // CHECK:STDERR: circle.radius = 5;
  34. // CHECK:STDERR: ^~~~~~~~~~~~~
  35. // CHECK:STDERR: fail_private_field_access.carbon:[[@LINE-25]]:15: note: declared here [ClassMemberDeclaration]
  36. // CHECK:STDERR: private var radius: i32;
  37. // CHECK:STDERR: ^~~~~~~~~~~
  38. // CHECK:STDERR:
  39. circle.radius = 5;
  40. // CHECK:STDERR: fail_private_field_access.carbon:[[@LINE+7]]:3: error: cannot access private member `SOME_INTERNAL_CONSTANT` of type `Circle` [ClassInvalidMemberAccess]
  41. // CHECK:STDERR: circle.SOME_INTERNAL_CONSTANT;
  42. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. // CHECK:STDERR: fail_private_field_access.carbon:[[@LINE-32]]:15: note: declared here [ClassMemberDeclaration]
  44. // CHECK:STDERR: private let SOME_INTERNAL_CONSTANT: i32 = 5;
  45. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
  46. // CHECK:STDERR:
  47. circle.SOME_INTERNAL_CONSTANT;
  48. // CHECK:STDERR: fail_private_field_access.carbon:[[@LINE+7]]:3: error: cannot access private member `SomeInternalFunction` of type `Circle` [ClassInvalidMemberAccess]
  49. // CHECK:STDERR: circle.SomeInternalFunction();
  50. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  51. // CHECK:STDERR: fail_private_field_access.carbon:[[@LINE-39]]:3: note: declared here [ClassMemberDeclaration]
  52. // CHECK:STDERR: private fn SomeInternalFunction() -> i32 {
  53. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  54. // CHECK:STDERR:
  55. circle.SomeInternalFunction();
  56. }
  57. // --- fail_protected_field_access.carbon
  58. library "[[@TEST_NAME]]";
  59. class A {
  60. protected var x: i32;
  61. }
  62. fn Run() {
  63. // CHECK:STDERR: fail_protected_field_access.carbon:[[@LINE+7]]:16: error: cannot access protected member `x` of type `A` [ClassInvalidMemberAccess]
  64. // CHECK:STDERR: let x: i32 = A.x;
  65. // CHECK:STDERR: ^~~
  66. // CHECK:STDERR: fail_protected_field_access.carbon:[[@LINE-7]]:17: note: declared here [ClassMemberDeclaration]
  67. // CHECK:STDERR: protected var x: i32;
  68. // CHECK:STDERR: ^~~~~~
  69. // CHECK:STDERR:
  70. let x: i32 = A.x;
  71. }
  72. // --- instance_private_field_access_on_self.carbon
  73. library "[[@TEST_NAME]]";
  74. class Circle {
  75. private var radius: i32;
  76. fn GetRadius[self: Self]() -> i32 {
  77. return self.radius;
  78. }
  79. private fn SomeInternalFunction() -> i32 {
  80. return 0;
  81. }
  82. fn Compute[self: Self]() -> i32 {
  83. return self.SomeInternalFunction();
  84. }
  85. }
  86. // --- public_global_access.carbon
  87. library "[[@TEST_NAME]]";
  88. class A {
  89. let x: i32 = 5;
  90. }
  91. let x: i32 = A.x;
  92. // --- fail_global_access.carbon
  93. library "[[@TEST_NAME]]";
  94. class A {
  95. protected let x: i32 = 5;
  96. private let y: i32 = 5;
  97. }
  98. // CHECK:STDERR: fail_global_access.carbon:[[@LINE+7]]:14: error: cannot access protected member `x` of type `A` [ClassInvalidMemberAccess]
  99. // CHECK:STDERR: let x: i32 = A.x;
  100. // CHECK:STDERR: ^~~
  101. // CHECK:STDERR: fail_global_access.carbon:[[@LINE-7]]:17: note: declared here [ClassMemberDeclaration]
  102. // CHECK:STDERR: protected let x: i32 = 5;
  103. // CHECK:STDERR: ^
  104. // CHECK:STDERR:
  105. let x: i32 = A.x;
  106. // CHECK:STDERR: fail_global_access.carbon:[[@LINE+6]]:14: error: cannot access private member `y` of type `A` [ClassInvalidMemberAccess]
  107. // CHECK:STDERR: let y: i32 = A.y;
  108. // CHECK:STDERR: ^~~
  109. // CHECK:STDERR: fail_global_access.carbon:[[@LINE-14]]:15: note: declared here [ClassMemberDeclaration]
  110. // CHECK:STDERR: private let y: i32 = 5;
  111. // CHECK:STDERR: ^
  112. let y: i32 = A.y;
  113. // --- self_access.carbon
  114. library "[[@TEST_NAME]]";
  115. class A {
  116. private fn F() {}
  117. private fn G() { Self.F(); }
  118. }
  119. // CHECK:STDOUT: --- fail_private_field_access.carbon
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: constants {
  122. // CHECK:STDOUT: %Circle: type = class_type @Circle [template]
  123. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  124. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  125. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  126. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  127. // CHECK:STDOUT: %.2: type = unbound_element_type %Circle, %i32 [template]
  128. // CHECK:STDOUT: %.3: Core.IntLiteral = int_value 5 [template]
  129. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  130. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  131. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  132. // CHECK:STDOUT: %.23: <witness> = interface_witness (%Convert.14) [template]
  133. // CHECK:STDOUT: %.24: <bound method> = bound_method %.3, %Convert.14 [template]
  134. // CHECK:STDOUT: %.25: <specific function> = specific_function %.24, @Convert.2(%.1) [template]
  135. // CHECK:STDOUT: %.26: %i32 = int_value 5 [template]
  136. // CHECK:STDOUT: %SomeInternalFunction.type: type = fn_type @SomeInternalFunction [template]
  137. // CHECK:STDOUT: %SomeInternalFunction: %SomeInternalFunction.type = struct_value () [template]
  138. // CHECK:STDOUT: %Make.type: type = fn_type @Make [template]
  139. // CHECK:STDOUT: %Make: %Make.type = struct_value () [template]
  140. // CHECK:STDOUT: %.27: type = struct_type {.radius: %i32} [template]
  141. // CHECK:STDOUT: %.28: <witness> = complete_type_witness %.27 [template]
  142. // CHECK:STDOUT: %.29: Core.IntLiteral = int_value 0 [template]
  143. // CHECK:STDOUT: %.30: <bound method> = bound_method %.29, %Convert.14 [template]
  144. // CHECK:STDOUT: %.31: <specific function> = specific_function %.30, @Convert.2(%.1) [template]
  145. // CHECK:STDOUT: %.32: %i32 = int_value 0 [template]
  146. // CHECK:STDOUT: %.34: type = struct_type {.radius: Core.IntLiteral} [template]
  147. // CHECK:STDOUT: %struct: %Circle = struct_value (%.26) [template]
  148. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  149. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: imports {
  153. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  154. // CHECK:STDOUT: .Int = %import_ref.1
  155. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  156. // CHECK:STDOUT: import Core//prelude
  157. // CHECK:STDOUT: import Core//prelude/...
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: file {
  162. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  163. // CHECK:STDOUT: .Core = imports.%Core
  164. // CHECK:STDOUT: .Circle = %Circle.decl
  165. // CHECK:STDOUT: .Run = %Run.decl
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT: %Core.import = import Core
  168. // CHECK:STDOUT: %Circle.decl: type = class_decl @Circle [template = constants.%Circle] {} {}
  169. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {} {}
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: class @Circle {
  173. // CHECK:STDOUT: %.loc5_23.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  174. // CHECK:STDOUT: %int.make_type_signed.loc5: init type = call constants.%Int(%.loc5_23.1) [template = constants.%i32]
  175. // CHECK:STDOUT: %.loc5_23.2: type = value_of_initializer %int.make_type_signed.loc5 [template = constants.%i32]
  176. // CHECK:STDOUT: %.loc5_23.3: type = converted %int.make_type_signed.loc5, %.loc5_23.2 [template = constants.%i32]
  177. // CHECK:STDOUT: %.loc5_21: %.2 = field_decl radius, element0 [template]
  178. // CHECK:STDOUT: %.loc6_39.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  179. // CHECK:STDOUT: %int.make_type_signed.loc6: init type = call constants.%Int(%.loc6_39.1) [template = constants.%i32]
  180. // CHECK:STDOUT: %.loc6_39.2: type = value_of_initializer %int.make_type_signed.loc6 [template = constants.%i32]
  181. // CHECK:STDOUT: %.loc6_39.3: type = converted %int.make_type_signed.loc6, %.loc6_39.2 [template = constants.%i32]
  182. // CHECK:STDOUT: %.loc6_45: Core.IntLiteral = int_value 5 [template = constants.%.3]
  183. // CHECK:STDOUT: %.loc6_46.1: %Convert.type.2 = interface_witness_access constants.%.23, element0 [template = constants.%Convert.14]
  184. // CHECK:STDOUT: %.loc6_46.2: <bound method> = bound_method %.loc6_45, %.loc6_46.1 [template = constants.%.24]
  185. // CHECK:STDOUT: %.loc6_46.3: <specific function> = specific_function %.loc6_46.2, @Convert.2(constants.%.1) [template = constants.%.25]
  186. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc6_46.3(%.loc6_45) [template = constants.%.26]
  187. // CHECK:STDOUT: %.loc6_46.4: %i32 = value_of_initializer %int.convert_checked [template = constants.%.26]
  188. // CHECK:STDOUT: %.loc6_46.5: %i32 = converted %.loc6_45, %.loc6_46.4 [template = constants.%.26]
  189. // CHECK:STDOUT: %SOME_INTERNAL_CONSTANT: %i32 = bind_name SOME_INTERNAL_CONSTANT, %.loc6_46.5
  190. // CHECK:STDOUT: %SomeInternalFunction.decl: %SomeInternalFunction.type = fn_decl @SomeInternalFunction [template = constants.%SomeInternalFunction] {
  191. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  192. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  193. // CHECK:STDOUT: } {
  194. // CHECK:STDOUT: %.loc8_40.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  195. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc8_40.1) [template = constants.%i32]
  196. // CHECK:STDOUT: %.loc8_40.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  197. // CHECK:STDOUT: %.loc8_40.3: type = converted %int.make_type_signed, %.loc8_40.2 [template = constants.%i32]
  198. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  199. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [template = constants.%Make] {
  202. // CHECK:STDOUT: %return.patt: %Circle = return_slot_pattern
  203. // CHECK:STDOUT: %return.param_patt: %Circle = out_param_pattern %return.patt, runtime_param0
  204. // CHECK:STDOUT: } {
  205. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Circle [template = constants.%Circle]
  206. // CHECK:STDOUT: %return.param: ref %Circle = out_param runtime_param0
  207. // CHECK:STDOUT: %return: ref %Circle = return_slot %return.param
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.27 [template = constants.%.28]
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: !members:
  212. // CHECK:STDOUT: .Self = constants.%Circle
  213. // CHECK:STDOUT: .radius [private] = %.loc5_21
  214. // CHECK:STDOUT: .SOME_INTERNAL_CONSTANT [private] = %SOME_INTERNAL_CONSTANT
  215. // CHECK:STDOUT: .SomeInternalFunction [private] = %SomeInternalFunction.decl
  216. // CHECK:STDOUT: .Make = %Make.decl
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: fn @SomeInternalFunction() -> %i32 {
  220. // CHECK:STDOUT: !entry:
  221. // CHECK:STDOUT: %.loc9_12: Core.IntLiteral = int_value 0 [template = constants.%.29]
  222. // CHECK:STDOUT: %.loc9_13.1: %Convert.type.2 = interface_witness_access constants.%.23, element0 [template = constants.%Convert.14]
  223. // CHECK:STDOUT: %.loc9_13.2: <bound method> = bound_method %.loc9_12, %.loc9_13.1 [template = constants.%.30]
  224. // CHECK:STDOUT: %.loc9_13.3: <specific function> = specific_function %.loc9_13.2, @Convert.2(constants.%.1) [template = constants.%.31]
  225. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc9_13.3(%.loc9_12) [template = constants.%.32]
  226. // CHECK:STDOUT: %.loc9_13.4: %i32 = value_of_initializer %int.convert_checked [template = constants.%.32]
  227. // CHECK:STDOUT: %.loc9_13.5: %i32 = converted %.loc9_12, %.loc9_13.4 [template = constants.%.32]
  228. // CHECK:STDOUT: return %.loc9_13.5
  229. // CHECK:STDOUT: }
  230. // CHECK:STDOUT:
  231. // CHECK:STDOUT: fn @Make() -> %return: %Circle {
  232. // CHECK:STDOUT: !entry:
  233. // CHECK:STDOUT: %.loc13_23: Core.IntLiteral = int_value 5 [template = constants.%.3]
  234. // CHECK:STDOUT: %.loc13_24.1: %.34 = struct_literal (%.loc13_23)
  235. // CHECK:STDOUT: %.loc13_24.2: %Convert.type.2 = interface_witness_access constants.%.23, element0 [template = constants.%Convert.14]
  236. // CHECK:STDOUT: %.loc13_24.3: <bound method> = bound_method %.loc13_23, %.loc13_24.2 [template = constants.%.24]
  237. // CHECK:STDOUT: %.loc13_24.4: <specific function> = specific_function %.loc13_24.3, @Convert.2(constants.%.1) [template = constants.%.25]
  238. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc13_24.4(%.loc13_23) [template = constants.%.26]
  239. // CHECK:STDOUT: %.loc13_24.5: init %i32 = converted %.loc13_23, %int.convert_checked [template = constants.%.26]
  240. // CHECK:STDOUT: %.loc13_24.6: ref %i32 = class_element_access %return, element0
  241. // CHECK:STDOUT: %.loc13_24.7: init %i32 = initialize_from %.loc13_24.5 to %.loc13_24.6 [template = constants.%.26]
  242. // CHECK:STDOUT: %.loc13_24.8: init %Circle = class_init (%.loc13_24.7), %return [template = constants.%struct]
  243. // CHECK:STDOUT: %.loc13_25: init %Circle = converted %.loc13_24.1, %.loc13_24.8 [template = constants.%struct]
  244. // CHECK:STDOUT: return %.loc13_25 to %return
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: fn @Run() {
  248. // CHECK:STDOUT: !entry:
  249. // CHECK:STDOUT: %Circle.ref.loc18_15: type = name_ref Circle, file.%Circle.decl [template = constants.%Circle]
  250. // CHECK:STDOUT: %Circle.ref.loc18_24: type = name_ref Circle, file.%Circle.decl [template = constants.%Circle]
  251. // CHECK:STDOUT: %Make.ref: %Make.type = name_ref Make, @Circle.%Make.decl [template = constants.%Make]
  252. // CHECK:STDOUT: %.loc18_35.1: ref %Circle = temporary_storage
  253. // CHECK:STDOUT: %Make.call: init %Circle = call %Make.ref() to %.loc18_35.1
  254. // CHECK:STDOUT: %.loc18_35.2: ref %Circle = temporary %.loc18_35.1, %Make.call
  255. // CHECK:STDOUT: %.loc18_35.3: %Circle = bind_value %.loc18_35.2
  256. // CHECK:STDOUT: %circle: %Circle = bind_name circle, %.loc18_35.3
  257. // CHECK:STDOUT: %.loc26_15.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  258. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc26_15.1) [template = constants.%i32]
  259. // CHECK:STDOUT: %.loc26_15.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  260. // CHECK:STDOUT: %.loc26_15.3: type = converted %int.make_type_signed, %.loc26_15.2 [template = constants.%i32]
  261. // CHECK:STDOUT: %circle.ref.loc26: %Circle = name_ref circle, %circle
  262. // CHECK:STDOUT: %radius.ref.loc26: <error> = name_ref radius, <error> [template = <error>]
  263. // CHECK:STDOUT: %radius: %i32 = bind_name radius, <error>
  264. // CHECK:STDOUT: %circle.ref.loc34: %Circle = name_ref circle, %circle
  265. // CHECK:STDOUT: %radius.ref.loc34: <error> = name_ref radius, <error> [template = <error>]
  266. // CHECK:STDOUT: %.loc34: Core.IntLiteral = int_value 5 [template = constants.%.3]
  267. // CHECK:STDOUT: assign %radius.ref.loc34, <error>
  268. // CHECK:STDOUT: %circle.ref.loc42: %Circle = name_ref circle, %circle
  269. // CHECK:STDOUT: %SOME_INTERNAL_CONSTANT.ref: <error> = name_ref SOME_INTERNAL_CONSTANT, <error> [template = <error>]
  270. // CHECK:STDOUT: %circle.ref.loc51: %Circle = name_ref circle, %circle
  271. // CHECK:STDOUT: %SomeInternalFunction.ref: <error> = name_ref SomeInternalFunction, <error> [template = <error>]
  272. // CHECK:STDOUT: return
  273. // CHECK:STDOUT: }
  274. // CHECK:STDOUT:
  275. // CHECK:STDOUT: --- fail_protected_field_access.carbon
  276. // CHECK:STDOUT:
  277. // CHECK:STDOUT: constants {
  278. // CHECK:STDOUT: %A: type = class_type @A [template]
  279. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  280. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  281. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  282. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  283. // CHECK:STDOUT: %.2: type = unbound_element_type %A, %i32 [template]
  284. // CHECK:STDOUT: %.3: type = struct_type {.x: %i32} [template]
  285. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  286. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  287. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  288. // CHECK:STDOUT: }
  289. // CHECK:STDOUT:
  290. // CHECK:STDOUT: imports {
  291. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  292. // CHECK:STDOUT: .Int = %import_ref
  293. // CHECK:STDOUT: import Core//prelude
  294. // CHECK:STDOUT: import Core//prelude/...
  295. // CHECK:STDOUT: }
  296. // CHECK:STDOUT: }
  297. // CHECK:STDOUT:
  298. // CHECK:STDOUT: file {
  299. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  300. // CHECK:STDOUT: .Core = imports.%Core
  301. // CHECK:STDOUT: .A = %A.decl
  302. // CHECK:STDOUT: .Run = %Run.decl
  303. // CHECK:STDOUT: }
  304. // CHECK:STDOUT: %Core.import = import Core
  305. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  306. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {} {}
  307. // CHECK:STDOUT: }
  308. // CHECK:STDOUT:
  309. // CHECK:STDOUT: class @A {
  310. // CHECK:STDOUT: %.loc5_20.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  311. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc5_20.1) [template = constants.%i32]
  312. // CHECK:STDOUT: %.loc5_20.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  313. // CHECK:STDOUT: %.loc5_20.3: type = converted %int.make_type_signed, %.loc5_20.2 [template = constants.%i32]
  314. // CHECK:STDOUT: %.loc5_18: %.2 = field_decl x, element0 [template]
  315. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.3 [template = constants.%.4]
  316. // CHECK:STDOUT:
  317. // CHECK:STDOUT: !members:
  318. // CHECK:STDOUT: .Self = constants.%A
  319. // CHECK:STDOUT: .x [protected] = %.loc5_18
  320. // CHECK:STDOUT: }
  321. // CHECK:STDOUT:
  322. // CHECK:STDOUT: fn @Run() {
  323. // CHECK:STDOUT: !entry:
  324. // CHECK:STDOUT: %.loc16_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  325. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc16_10.1) [template = constants.%i32]
  326. // CHECK:STDOUT: %.loc16_10.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  327. // CHECK:STDOUT: %.loc16_10.3: type = converted %int.make_type_signed, %.loc16_10.2 [template = constants.%i32]
  328. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  329. // CHECK:STDOUT: %x.ref: <error> = name_ref x, <error> [template = <error>]
  330. // CHECK:STDOUT: %x: %i32 = bind_name x, <error>
  331. // CHECK:STDOUT: return
  332. // CHECK:STDOUT: }
  333. // CHECK:STDOUT:
  334. // CHECK:STDOUT: --- instance_private_field_access_on_self.carbon
  335. // CHECK:STDOUT:
  336. // CHECK:STDOUT: constants {
  337. // CHECK:STDOUT: %Circle: type = class_type @Circle [template]
  338. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  339. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  340. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  341. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  342. // CHECK:STDOUT: %.2: type = unbound_element_type %Circle, %i32 [template]
  343. // CHECK:STDOUT: %GetRadius.type: type = fn_type @GetRadius [template]
  344. // CHECK:STDOUT: %GetRadius: %GetRadius.type = struct_value () [template]
  345. // CHECK:STDOUT: %SomeInternalFunction.type: type = fn_type @SomeInternalFunction [template]
  346. // CHECK:STDOUT: %SomeInternalFunction: %SomeInternalFunction.type = struct_value () [template]
  347. // CHECK:STDOUT: %Compute.type: type = fn_type @Compute [template]
  348. // CHECK:STDOUT: %Compute: %Compute.type = struct_value () [template]
  349. // CHECK:STDOUT: %.3: type = struct_type {.radius: %i32} [template]
  350. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  351. // CHECK:STDOUT: %.6: Core.IntLiteral = int_value 0 [template]
  352. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  353. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  354. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  355. // CHECK:STDOUT: %.26: <witness> = interface_witness (%Convert.14) [template]
  356. // CHECK:STDOUT: %.27: <bound method> = bound_method %.6, %Convert.14 [template]
  357. // CHECK:STDOUT: %.28: <specific function> = specific_function %.27, @Convert.2(%.1) [template]
  358. // CHECK:STDOUT: %.29: %i32 = int_value 0 [template]
  359. // CHECK:STDOUT: }
  360. // CHECK:STDOUT:
  361. // CHECK:STDOUT: imports {
  362. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  363. // CHECK:STDOUT: .Int = %import_ref.1
  364. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  365. // CHECK:STDOUT: import Core//prelude
  366. // CHECK:STDOUT: import Core//prelude/...
  367. // CHECK:STDOUT: }
  368. // CHECK:STDOUT: }
  369. // CHECK:STDOUT:
  370. // CHECK:STDOUT: file {
  371. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  372. // CHECK:STDOUT: .Core = imports.%Core
  373. // CHECK:STDOUT: .Circle = %Circle.decl
  374. // CHECK:STDOUT: }
  375. // CHECK:STDOUT: %Core.import = import Core
  376. // CHECK:STDOUT: %Circle.decl: type = class_decl @Circle [template = constants.%Circle] {} {}
  377. // CHECK:STDOUT: }
  378. // CHECK:STDOUT:
  379. // CHECK:STDOUT: class @Circle {
  380. // CHECK:STDOUT: %.loc5_23.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  381. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc5_23.1) [template = constants.%i32]
  382. // CHECK:STDOUT: %.loc5_23.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  383. // CHECK:STDOUT: %.loc5_23.3: type = converted %int.make_type_signed, %.loc5_23.2 [template = constants.%i32]
  384. // CHECK:STDOUT: %.loc5_21: %.2 = field_decl radius, element0 [template]
  385. // CHECK:STDOUT: %GetRadius.decl: %GetRadius.type = fn_decl @GetRadius [template = constants.%GetRadius] {
  386. // CHECK:STDOUT: %self.patt: %Circle = binding_pattern self
  387. // CHECK:STDOUT: %self.param_patt: %Circle = value_param_pattern %self.patt, runtime_param0
  388. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  389. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  390. // CHECK:STDOUT: } {
  391. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Circle [template = constants.%Circle]
  392. // CHECK:STDOUT: %.loc7_33.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  393. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc7_33.1) [template = constants.%i32]
  394. // CHECK:STDOUT: %.loc7_33.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  395. // CHECK:STDOUT: %.loc7_33.3: type = converted %int.make_type_signed, %.loc7_33.2 [template = constants.%i32]
  396. // CHECK:STDOUT: %self.param: %Circle = value_param runtime_param0
  397. // CHECK:STDOUT: %self: %Circle = bind_name self, %self.param
  398. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  399. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  400. // CHECK:STDOUT: }
  401. // CHECK:STDOUT: %SomeInternalFunction.decl: %SomeInternalFunction.type = fn_decl @SomeInternalFunction [template = constants.%SomeInternalFunction] {
  402. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  403. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  404. // CHECK:STDOUT: } {
  405. // CHECK:STDOUT: %.loc11_40.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  406. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc11_40.1) [template = constants.%i32]
  407. // CHECK:STDOUT: %.loc11_40.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  408. // CHECK:STDOUT: %.loc11_40.3: type = converted %int.make_type_signed, %.loc11_40.2 [template = constants.%i32]
  409. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  410. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  411. // CHECK:STDOUT: }
  412. // CHECK:STDOUT: %Compute.decl: %Compute.type = fn_decl @Compute [template = constants.%Compute] {
  413. // CHECK:STDOUT: %self.patt: %Circle = binding_pattern self
  414. // CHECK:STDOUT: %self.param_patt: %Circle = value_param_pattern %self.patt, runtime_param0
  415. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  416. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  417. // CHECK:STDOUT: } {
  418. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Circle [template = constants.%Circle]
  419. // CHECK:STDOUT: %.loc15_31.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  420. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc15_31.1) [template = constants.%i32]
  421. // CHECK:STDOUT: %.loc15_31.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  422. // CHECK:STDOUT: %.loc15_31.3: type = converted %int.make_type_signed, %.loc15_31.2 [template = constants.%i32]
  423. // CHECK:STDOUT: %self.param: %Circle = value_param runtime_param0
  424. // CHECK:STDOUT: %self: %Circle = bind_name self, %self.param
  425. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  426. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  427. // CHECK:STDOUT: }
  428. // CHECK:STDOUT: %.loc18: <witness> = complete_type_witness %.3 [template = constants.%.4]
  429. // CHECK:STDOUT:
  430. // CHECK:STDOUT: !members:
  431. // CHECK:STDOUT: .Self = constants.%Circle
  432. // CHECK:STDOUT: .radius [private] = %.loc5_21
  433. // CHECK:STDOUT: .GetRadius = %GetRadius.decl
  434. // CHECK:STDOUT: .SomeInternalFunction [private] = %SomeInternalFunction.decl
  435. // CHECK:STDOUT: .Compute = %Compute.decl
  436. // CHECK:STDOUT: }
  437. // CHECK:STDOUT:
  438. // CHECK:STDOUT: fn @GetRadius[%self.param_patt: %Circle]() -> %i32 {
  439. // CHECK:STDOUT: !entry:
  440. // CHECK:STDOUT: %self.ref: %Circle = name_ref self, %self
  441. // CHECK:STDOUT: %radius.ref: %.2 = name_ref radius, @Circle.%.loc5_21 [template = @Circle.%.loc5_21]
  442. // CHECK:STDOUT: %.loc8_16.1: ref %i32 = class_element_access %self.ref, element0
  443. // CHECK:STDOUT: %.loc8_16.2: %i32 = bind_value %.loc8_16.1
  444. // CHECK:STDOUT: return %.loc8_16.2
  445. // CHECK:STDOUT: }
  446. // CHECK:STDOUT:
  447. // CHECK:STDOUT: fn @SomeInternalFunction() -> %i32 {
  448. // CHECK:STDOUT: !entry:
  449. // CHECK:STDOUT: %.loc12_12: Core.IntLiteral = int_value 0 [template = constants.%.6]
  450. // CHECK:STDOUT: %.loc12_13.1: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  451. // CHECK:STDOUT: %.loc12_13.2: <bound method> = bound_method %.loc12_12, %.loc12_13.1 [template = constants.%.27]
  452. // CHECK:STDOUT: %.loc12_13.3: <specific function> = specific_function %.loc12_13.2, @Convert.2(constants.%.1) [template = constants.%.28]
  453. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc12_13.3(%.loc12_12) [template = constants.%.29]
  454. // CHECK:STDOUT: %.loc12_13.4: %i32 = value_of_initializer %int.convert_checked [template = constants.%.29]
  455. // CHECK:STDOUT: %.loc12_13.5: %i32 = converted %.loc12_12, %.loc12_13.4 [template = constants.%.29]
  456. // CHECK:STDOUT: return %.loc12_13.5
  457. // CHECK:STDOUT: }
  458. // CHECK:STDOUT:
  459. // CHECK:STDOUT: fn @Compute[%self.param_patt: %Circle]() -> %i32 {
  460. // CHECK:STDOUT: !entry:
  461. // CHECK:STDOUT: %self.ref: %Circle = name_ref self, %self
  462. // CHECK:STDOUT: %SomeInternalFunction.ref: %SomeInternalFunction.type = name_ref SomeInternalFunction, @Circle.%SomeInternalFunction.decl [template = constants.%SomeInternalFunction]
  463. // CHECK:STDOUT: %SomeInternalFunction.call: init %i32 = call %SomeInternalFunction.ref()
  464. // CHECK:STDOUT: %.loc16_39.1: %i32 = value_of_initializer %SomeInternalFunction.call
  465. // CHECK:STDOUT: %.loc16_39.2: %i32 = converted %SomeInternalFunction.call, %.loc16_39.1
  466. // CHECK:STDOUT: return %.loc16_39.2
  467. // CHECK:STDOUT: }
  468. // CHECK:STDOUT:
  469. // CHECK:STDOUT: --- public_global_access.carbon
  470. // CHECK:STDOUT:
  471. // CHECK:STDOUT: constants {
  472. // CHECK:STDOUT: %A: type = class_type @A [template]
  473. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  474. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  475. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  476. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  477. // CHECK:STDOUT: %.2: Core.IntLiteral = int_value 5 [template]
  478. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  479. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  480. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  481. // CHECK:STDOUT: %.22: <witness> = interface_witness (%Convert.14) [template]
  482. // CHECK:STDOUT: %.23: <bound method> = bound_method %.2, %Convert.14 [template]
  483. // CHECK:STDOUT: %.24: <specific function> = specific_function %.23, @Convert.2(%.1) [template]
  484. // CHECK:STDOUT: %.25: %i32 = int_value 5 [template]
  485. // CHECK:STDOUT: %.26: type = struct_type {} [template]
  486. // CHECK:STDOUT: %.27: <witness> = complete_type_witness %.26 [template]
  487. // CHECK:STDOUT: }
  488. // CHECK:STDOUT:
  489. // CHECK:STDOUT: imports {
  490. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  491. // CHECK:STDOUT: .Int = %import_ref.1
  492. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  493. // CHECK:STDOUT: import Core//prelude
  494. // CHECK:STDOUT: import Core//prelude/...
  495. // CHECK:STDOUT: }
  496. // CHECK:STDOUT: }
  497. // CHECK:STDOUT:
  498. // CHECK:STDOUT: file {
  499. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  500. // CHECK:STDOUT: .Core = imports.%Core
  501. // CHECK:STDOUT: .A = %A.decl
  502. // CHECK:STDOUT: .x = @__global_init.%x
  503. // CHECK:STDOUT: }
  504. // CHECK:STDOUT: %Core.import = import Core
  505. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  506. // CHECK:STDOUT: %.loc8_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  507. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc8_8.1) [template = constants.%i32]
  508. // CHECK:STDOUT: %.loc8_8.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  509. // CHECK:STDOUT: %.loc8_8.3: type = converted %int.make_type_signed, %.loc8_8.2 [template = constants.%i32]
  510. // CHECK:STDOUT: }
  511. // CHECK:STDOUT:
  512. // CHECK:STDOUT: class @A {
  513. // CHECK:STDOUT: %.loc5_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  514. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc5_10.1) [template = constants.%i32]
  515. // CHECK:STDOUT: %.loc5_10.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  516. // CHECK:STDOUT: %.loc5_10.3: type = converted %int.make_type_signed, %.loc5_10.2 [template = constants.%i32]
  517. // CHECK:STDOUT: %.loc5_16: Core.IntLiteral = int_value 5 [template = constants.%.2]
  518. // CHECK:STDOUT: %.loc5_17.1: %Convert.type.2 = interface_witness_access constants.%.22, element0 [template = constants.%Convert.14]
  519. // CHECK:STDOUT: %.loc5_17.2: <bound method> = bound_method %.loc5_16, %.loc5_17.1 [template = constants.%.23]
  520. // CHECK:STDOUT: %.loc5_17.3: <specific function> = specific_function %.loc5_17.2, @Convert.2(constants.%.1) [template = constants.%.24]
  521. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc5_17.3(%.loc5_16) [template = constants.%.25]
  522. // CHECK:STDOUT: %.loc5_17.4: %i32 = value_of_initializer %int.convert_checked [template = constants.%.25]
  523. // CHECK:STDOUT: %.loc5_17.5: %i32 = converted %.loc5_16, %.loc5_17.4 [template = constants.%.25]
  524. // CHECK:STDOUT: %x: %i32 = bind_name x, %.loc5_17.5
  525. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.26 [template = constants.%.27]
  526. // CHECK:STDOUT:
  527. // CHECK:STDOUT: !members:
  528. // CHECK:STDOUT: .Self = constants.%A
  529. // CHECK:STDOUT: .x = %x
  530. // CHECK:STDOUT: }
  531. // CHECK:STDOUT:
  532. // CHECK:STDOUT: fn @__global_init() {
  533. // CHECK:STDOUT: !entry:
  534. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  535. // CHECK:STDOUT: %x.ref: %i32 = name_ref x, @A.%x
  536. // CHECK:STDOUT: %x: %i32 = bind_name x, %x.ref
  537. // CHECK:STDOUT: return
  538. // CHECK:STDOUT: }
  539. // CHECK:STDOUT:
  540. // CHECK:STDOUT: --- fail_global_access.carbon
  541. // CHECK:STDOUT:
  542. // CHECK:STDOUT: constants {
  543. // CHECK:STDOUT: %A: type = class_type @A [template]
  544. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  545. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  546. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  547. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  548. // CHECK:STDOUT: %.2: Core.IntLiteral = int_value 5 [template]
  549. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  550. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  551. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  552. // CHECK:STDOUT: %.22: <witness> = interface_witness (%Convert.14) [template]
  553. // CHECK:STDOUT: %.23: <bound method> = bound_method %.2, %Convert.14 [template]
  554. // CHECK:STDOUT: %.24: <specific function> = specific_function %.23, @Convert.2(%.1) [template]
  555. // CHECK:STDOUT: %.25: %i32 = int_value 5 [template]
  556. // CHECK:STDOUT: %.26: type = struct_type {} [template]
  557. // CHECK:STDOUT: %.27: <witness> = complete_type_witness %.26 [template]
  558. // CHECK:STDOUT: }
  559. // CHECK:STDOUT:
  560. // CHECK:STDOUT: imports {
  561. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  562. // CHECK:STDOUT: .Int = %import_ref.1
  563. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  564. // CHECK:STDOUT: import Core//prelude
  565. // CHECK:STDOUT: import Core//prelude/...
  566. // CHECK:STDOUT: }
  567. // CHECK:STDOUT: }
  568. // CHECK:STDOUT:
  569. // CHECK:STDOUT: file {
  570. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  571. // CHECK:STDOUT: .Core = imports.%Core
  572. // CHECK:STDOUT: .A = %A.decl
  573. // CHECK:STDOUT: .x = @__global_init.%x
  574. // CHECK:STDOUT: .y = @__global_init.%y
  575. // CHECK:STDOUT: }
  576. // CHECK:STDOUT: %Core.import = import Core
  577. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  578. // CHECK:STDOUT: %.loc16_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  579. // CHECK:STDOUT: %int.make_type_signed.loc16: init type = call constants.%Int(%.loc16_8.1) [template = constants.%i32]
  580. // CHECK:STDOUT: %.loc16_8.2: type = value_of_initializer %int.make_type_signed.loc16 [template = constants.%i32]
  581. // CHECK:STDOUT: %.loc16_8.3: type = converted %int.make_type_signed.loc16, %.loc16_8.2 [template = constants.%i32]
  582. // CHECK:STDOUT: %.loc23_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  583. // CHECK:STDOUT: %int.make_type_signed.loc23: init type = call constants.%Int(%.loc23_8.1) [template = constants.%i32]
  584. // CHECK:STDOUT: %.loc23_8.2: type = value_of_initializer %int.make_type_signed.loc23 [template = constants.%i32]
  585. // CHECK:STDOUT: %.loc23_8.3: type = converted %int.make_type_signed.loc23, %.loc23_8.2 [template = constants.%i32]
  586. // CHECK:STDOUT: }
  587. // CHECK:STDOUT:
  588. // CHECK:STDOUT: class @A {
  589. // CHECK:STDOUT: %.loc5_20.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  590. // CHECK:STDOUT: %int.make_type_signed.loc5: init type = call constants.%Int(%.loc5_20.1) [template = constants.%i32]
  591. // CHECK:STDOUT: %.loc5_20.2: type = value_of_initializer %int.make_type_signed.loc5 [template = constants.%i32]
  592. // CHECK:STDOUT: %.loc5_20.3: type = converted %int.make_type_signed.loc5, %.loc5_20.2 [template = constants.%i32]
  593. // CHECK:STDOUT: %.loc5_26: Core.IntLiteral = int_value 5 [template = constants.%.2]
  594. // CHECK:STDOUT: %.loc5_27.1: %Convert.type.2 = interface_witness_access constants.%.22, element0 [template = constants.%Convert.14]
  595. // CHECK:STDOUT: %.loc5_27.2: <bound method> = bound_method %.loc5_26, %.loc5_27.1 [template = constants.%.23]
  596. // CHECK:STDOUT: %.loc5_27.3: <specific function> = specific_function %.loc5_27.2, @Convert.2(constants.%.1) [template = constants.%.24]
  597. // CHECK:STDOUT: %int.convert_checked.loc5: init %i32 = call %.loc5_27.3(%.loc5_26) [template = constants.%.25]
  598. // CHECK:STDOUT: %.loc5_27.4: %i32 = value_of_initializer %int.convert_checked.loc5 [template = constants.%.25]
  599. // CHECK:STDOUT: %.loc5_27.5: %i32 = converted %.loc5_26, %.loc5_27.4 [template = constants.%.25]
  600. // CHECK:STDOUT: %x: %i32 = bind_name x, %.loc5_27.5
  601. // CHECK:STDOUT: %.loc6_18.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  602. // CHECK:STDOUT: %int.make_type_signed.loc6: init type = call constants.%Int(%.loc6_18.1) [template = constants.%i32]
  603. // CHECK:STDOUT: %.loc6_18.2: type = value_of_initializer %int.make_type_signed.loc6 [template = constants.%i32]
  604. // CHECK:STDOUT: %.loc6_18.3: type = converted %int.make_type_signed.loc6, %.loc6_18.2 [template = constants.%i32]
  605. // CHECK:STDOUT: %.loc6_24: Core.IntLiteral = int_value 5 [template = constants.%.2]
  606. // CHECK:STDOUT: %.loc6_25.1: %Convert.type.2 = interface_witness_access constants.%.22, element0 [template = constants.%Convert.14]
  607. // CHECK:STDOUT: %.loc6_25.2: <bound method> = bound_method %.loc6_24, %.loc6_25.1 [template = constants.%.23]
  608. // CHECK:STDOUT: %.loc6_25.3: <specific function> = specific_function %.loc6_25.2, @Convert.2(constants.%.1) [template = constants.%.24]
  609. // CHECK:STDOUT: %int.convert_checked.loc6: init %i32 = call %.loc6_25.3(%.loc6_24) [template = constants.%.25]
  610. // CHECK:STDOUT: %.loc6_25.4: %i32 = value_of_initializer %int.convert_checked.loc6 [template = constants.%.25]
  611. // CHECK:STDOUT: %.loc6_25.5: %i32 = converted %.loc6_24, %.loc6_25.4 [template = constants.%.25]
  612. // CHECK:STDOUT: %y: %i32 = bind_name y, %.loc6_25.5
  613. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.26 [template = constants.%.27]
  614. // CHECK:STDOUT:
  615. // CHECK:STDOUT: !members:
  616. // CHECK:STDOUT: .Self = constants.%A
  617. // CHECK:STDOUT: .x [protected] = %x
  618. // CHECK:STDOUT: .y [private] = %y
  619. // CHECK:STDOUT: }
  620. // CHECK:STDOUT:
  621. // CHECK:STDOUT: fn @__global_init() {
  622. // CHECK:STDOUT: !entry:
  623. // CHECK:STDOUT: %A.ref.loc16: type = name_ref A, file.%A.decl [template = constants.%A]
  624. // CHECK:STDOUT: %x.ref: <error> = name_ref x, <error> [template = <error>]
  625. // CHECK:STDOUT: %x: %i32 = bind_name x, <error>
  626. // CHECK:STDOUT: %A.ref.loc23: type = name_ref A, file.%A.decl [template = constants.%A]
  627. // CHECK:STDOUT: %y.ref: <error> = name_ref y, <error> [template = <error>]
  628. // CHECK:STDOUT: %y: %i32 = bind_name y, <error>
  629. // CHECK:STDOUT: return
  630. // CHECK:STDOUT: }
  631. // CHECK:STDOUT:
  632. // CHECK:STDOUT: --- self_access.carbon
  633. // CHECK:STDOUT:
  634. // CHECK:STDOUT: constants {
  635. // CHECK:STDOUT: %A: type = class_type @A [template]
  636. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  637. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  638. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  639. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  640. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  641. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  642. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  643. // CHECK:STDOUT: }
  644. // CHECK:STDOUT:
  645. // CHECK:STDOUT: imports {
  646. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  647. // CHECK:STDOUT: import Core//prelude
  648. // CHECK:STDOUT: import Core//prelude/...
  649. // CHECK:STDOUT: }
  650. // CHECK:STDOUT: }
  651. // CHECK:STDOUT:
  652. // CHECK:STDOUT: file {
  653. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  654. // CHECK:STDOUT: .Core = imports.%Core
  655. // CHECK:STDOUT: .A = %A.decl
  656. // CHECK:STDOUT: }
  657. // CHECK:STDOUT: %Core.import = import Core
  658. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  659. // CHECK:STDOUT: }
  660. // CHECK:STDOUT:
  661. // CHECK:STDOUT: class @A {
  662. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  663. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  664. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.1 [template = constants.%.2]
  665. // CHECK:STDOUT:
  666. // CHECK:STDOUT: !members:
  667. // CHECK:STDOUT: .Self = constants.%A
  668. // CHECK:STDOUT: .F [private] = %F.decl
  669. // CHECK:STDOUT: .G [private] = %G.decl
  670. // CHECK:STDOUT: }
  671. // CHECK:STDOUT:
  672. // CHECK:STDOUT: fn @F() {
  673. // CHECK:STDOUT: !entry:
  674. // CHECK:STDOUT: return
  675. // CHECK:STDOUT: }
  676. // CHECK:STDOUT:
  677. // CHECK:STDOUT: fn @G() {
  678. // CHECK:STDOUT: !entry:
  679. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%A [template = constants.%A]
  680. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @A.%F.decl [template = constants.%F]
  681. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  682. // CHECK:STDOUT: return
  683. // CHECK:STDOUT: }
  684. // CHECK:STDOUT: