adapter_conversion.carbon 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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/as/adapter_conversion.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/as/adapter_conversion.carbon
  10. // --- adapt_class.carbon
  11. library "[[@TEST_NAME]]";
  12. class A {
  13. var x: i32;
  14. var y: i32;
  15. fn Make() -> A {
  16. return {.x = 1, .y = 2};
  17. }
  18. }
  19. class B {
  20. adapt A;
  21. }
  22. var a_ref: A = {.x = 1, .y = 2};
  23. let a_val: A = a_ref;
  24. // An `as` conversion to an adapter type preserves the expression category.
  25. let b_val: B = a_val as B;
  26. let b_ptr: B* = &(a_ref as B);
  27. var b_factory: B = A.Make() as B;
  28. // --- adapt_i32.carbon
  29. library "[[@TEST_NAME]]";
  30. class A {
  31. adapt i32;
  32. }
  33. let a: A = (1 as i32) as A;
  34. let n: i32 = a as i32;
  35. // --- multi_level_adapt.carbon
  36. library "[[@TEST_NAME]]";
  37. class A { adapt {}; }
  38. class B { adapt A; }
  39. class C { adapt B; }
  40. class D { adapt C; }
  41. let d: D = {} as D;
  42. // --- fail_init_class.carbon
  43. library "[[@TEST_NAME]]";
  44. class A {
  45. var x: i32;
  46. var y: i32;
  47. }
  48. class B {
  49. adapt A;
  50. }
  51. let b_value: B = ({.x = 1, .y = 2} as A) as B;
  52. // TODO: Here, we treat `{.x = 1, .y = 2} as A` as a value expression, not an
  53. // initializing expression, so `(...) as B` is a value expression too, requiring
  54. // a copy to perform initialization. It's not clear whether that is the right
  55. // behavior.
  56. // CHECK:STDERR: fail_init_class.carbon:[[@LINE+4]]:17: error: cannot copy value of type `B` [CopyOfUncopyableType]
  57. // CHECK:STDERR: var b_init: B = ({.x = 1, .y = 2} as A) as B;
  58. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. // CHECK:STDERR:
  60. var b_init: B = ({.x = 1, .y = 2} as A) as B;
  61. // --- fail_adapt_init_from_struct.carbon
  62. library "[[@TEST_NAME]]";
  63. class A {
  64. var x: i32;
  65. }
  66. class B {
  67. adapt A;
  68. }
  69. // We do not try to implicitly convert from the first operand of `as` to the
  70. // adapted type of the second operand.
  71. // CHECK:STDERR: fail_adapt_init_from_struct.carbon:[[@LINE+6]]:12: error: cannot convert from `{.x: Core.IntLiteral}` to `B` with `as` [ExplicitAsConversionFailure]
  72. // CHECK:STDERR: var b: B = {.x = 1} as B;
  73. // CHECK:STDERR: ^~~~~~~~~~~~~
  74. // CHECK:STDERR: fail_adapt_init_from_struct.carbon:[[@LINE+3]]:12: note: type `{.x: Core.IntLiteral}` does not implement interface `As(B)` [MissingImplInMemberAccessNote]
  75. // CHECK:STDERR: var b: B = {.x = 1} as B;
  76. // CHECK:STDERR: ^~~~~~~~~~~~~
  77. var b: B = {.x = 1} as B;
  78. // CHECK:STDOUT: --- adapt_class.carbon
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: constants {
  81. // CHECK:STDOUT: %A: type = class_type @A [template]
  82. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  83. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  84. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  85. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  86. // CHECK:STDOUT: %.2: type = unbound_element_type %A, %i32 [template]
  87. // CHECK:STDOUT: %Make.type: type = fn_type @Make [template]
  88. // CHECK:STDOUT: %Make: %Make.type = struct_value () [template]
  89. // CHECK:STDOUT: %.3: type = struct_type {.x: %i32, .y: %i32} [template]
  90. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  91. // CHECK:STDOUT: %.6: Core.IntLiteral = int_value 1 [template]
  92. // CHECK:STDOUT: %.7: Core.IntLiteral = int_value 2 [template]
  93. // CHECK:STDOUT: %.8: type = struct_type {.x: Core.IntLiteral, .y: Core.IntLiteral} [template]
  94. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  95. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  96. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  97. // CHECK:STDOUT: %.32: <witness> = interface_witness (%Convert.14) [template]
  98. // CHECK:STDOUT: %.33: <bound method> = bound_method %.6, %Convert.14 [template]
  99. // CHECK:STDOUT: %.34: <specific function> = specific_function %.33, @Convert.2(%.1) [template]
  100. // CHECK:STDOUT: %.35: %i32 = int_value 1 [template]
  101. // CHECK:STDOUT: %.36: <bound method> = bound_method %.7, %Convert.14 [template]
  102. // CHECK:STDOUT: %.37: <specific function> = specific_function %.36, @Convert.2(%.1) [template]
  103. // CHECK:STDOUT: %.38: %i32 = int_value 2 [template]
  104. // CHECK:STDOUT: %struct: %A = struct_value (%.35, %.38) [template]
  105. // CHECK:STDOUT: %B: type = class_type @B [template]
  106. // CHECK:STDOUT: %.39: type = ptr_type %B [template]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: imports {
  110. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  111. // CHECK:STDOUT: .Int = %import_ref.1
  112. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  113. // CHECK:STDOUT: import Core//prelude
  114. // CHECK:STDOUT: import Core//prelude/...
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: file {
  119. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  120. // CHECK:STDOUT: .Core = imports.%Core
  121. // CHECK:STDOUT: .A = %A.decl
  122. // CHECK:STDOUT: .B = %B.decl
  123. // CHECK:STDOUT: .a_ref = %a_ref
  124. // CHECK:STDOUT: .a_val = @__global_init.%a_val
  125. // CHECK:STDOUT: .b_val = @__global_init.%b_val
  126. // CHECK:STDOUT: .b_ptr = @__global_init.%b_ptr
  127. // CHECK:STDOUT: .b_factory = %b_factory
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: %Core.import = import Core
  130. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  131. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  132. // CHECK:STDOUT: %A.ref.loc17: type = name_ref A, %A.decl [template = constants.%A]
  133. // CHECK:STDOUT: %a_ref.var: ref %A = var a_ref
  134. // CHECK:STDOUT: %a_ref: ref %A = bind_name a_ref, %a_ref.var
  135. // CHECK:STDOUT: %A.ref.loc18: type = name_ref A, %A.decl [template = constants.%A]
  136. // CHECK:STDOUT: %B.ref.loc21: type = name_ref B, %B.decl [template = constants.%B]
  137. // CHECK:STDOUT: %B.ref.loc22: type = name_ref B, %B.decl [template = constants.%B]
  138. // CHECK:STDOUT: %.loc22: type = ptr_type %B [template = constants.%.39]
  139. // CHECK:STDOUT: %B.ref.loc24: type = name_ref B, %B.decl [template = constants.%B]
  140. // CHECK:STDOUT: %b_factory.var: ref %B = var b_factory
  141. // CHECK:STDOUT: %b_factory: ref %B = bind_name b_factory, %b_factory.var
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: class @A {
  145. // CHECK:STDOUT: %.loc5_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  146. // CHECK:STDOUT: %int.make_type_signed.loc5: init type = call constants.%Int(%.loc5_10.1) [template = constants.%i32]
  147. // CHECK:STDOUT: %.loc5_10.2: type = value_of_initializer %int.make_type_signed.loc5 [template = constants.%i32]
  148. // CHECK:STDOUT: %.loc5_10.3: type = converted %int.make_type_signed.loc5, %.loc5_10.2 [template = constants.%i32]
  149. // CHECK:STDOUT: %.loc5_8: %.2 = field_decl x, element0 [template]
  150. // CHECK:STDOUT: %.loc6_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  151. // CHECK:STDOUT: %int.make_type_signed.loc6: init type = call constants.%Int(%.loc6_10.1) [template = constants.%i32]
  152. // CHECK:STDOUT: %.loc6_10.2: type = value_of_initializer %int.make_type_signed.loc6 [template = constants.%i32]
  153. // CHECK:STDOUT: %.loc6_10.3: type = converted %int.make_type_signed.loc6, %.loc6_10.2 [template = constants.%i32]
  154. // CHECK:STDOUT: %.loc6_8: %.2 = field_decl y, element1 [template]
  155. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [template = constants.%Make] {
  156. // CHECK:STDOUT: %return.patt: %A = return_slot_pattern
  157. // CHECK:STDOUT: %return.param_patt: %A = out_param_pattern %return.patt, runtime_param0
  158. // CHECK:STDOUT: } {
  159. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  160. // CHECK:STDOUT: %return.param: ref %A = out_param runtime_param0
  161. // CHECK:STDOUT: %return: ref %A = return_slot %return.param
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %.3 [template = constants.%.4]
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: !members:
  166. // CHECK:STDOUT: .Self = constants.%A
  167. // CHECK:STDOUT: .x = %.loc5_8
  168. // CHECK:STDOUT: .y = %.loc6_8
  169. // CHECK:STDOUT: .Make = %Make.decl
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: class @B {
  173. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  174. // CHECK:STDOUT: adapt_decl %A.ref [template]
  175. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.3 [template = constants.%.4]
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: !members:
  178. // CHECK:STDOUT: .Self = constants.%B
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: fn @Make() -> %return: %A {
  182. // CHECK:STDOUT: !entry:
  183. // CHECK:STDOUT: %.loc9_18: Core.IntLiteral = int_value 1 [template = constants.%.6]
  184. // CHECK:STDOUT: %.loc9_26: Core.IntLiteral = int_value 2 [template = constants.%.7]
  185. // CHECK:STDOUT: %.loc9_27.1: %.8 = struct_literal (%.loc9_18, %.loc9_26)
  186. // CHECK:STDOUT: %.loc9_27.2: %Convert.type.2 = interface_witness_access constants.%.32, element0 [template = constants.%Convert.14]
  187. // CHECK:STDOUT: %.loc9_27.3: <bound method> = bound_method %.loc9_18, %.loc9_27.2 [template = constants.%.33]
  188. // CHECK:STDOUT: %.loc9_27.4: <specific function> = specific_function %.loc9_27.3, @Convert.2(constants.%.1) [template = constants.%.34]
  189. // CHECK:STDOUT: %int.convert_checked.loc9_27.1: init %i32 = call %.loc9_27.4(%.loc9_18) [template = constants.%.35]
  190. // CHECK:STDOUT: %.loc9_27.5: init %i32 = converted %.loc9_18, %int.convert_checked.loc9_27.1 [template = constants.%.35]
  191. // CHECK:STDOUT: %.loc9_27.6: ref %i32 = class_element_access %return, element0
  192. // CHECK:STDOUT: %.loc9_27.7: init %i32 = initialize_from %.loc9_27.5 to %.loc9_27.6 [template = constants.%.35]
  193. // CHECK:STDOUT: %.loc9_27.8: %Convert.type.2 = interface_witness_access constants.%.32, element0 [template = constants.%Convert.14]
  194. // CHECK:STDOUT: %.loc9_27.9: <bound method> = bound_method %.loc9_26, %.loc9_27.8 [template = constants.%.36]
  195. // CHECK:STDOUT: %.loc9_27.10: <specific function> = specific_function %.loc9_27.9, @Convert.2(constants.%.1) [template = constants.%.37]
  196. // CHECK:STDOUT: %int.convert_checked.loc9_27.2: init %i32 = call %.loc9_27.10(%.loc9_26) [template = constants.%.38]
  197. // CHECK:STDOUT: %.loc9_27.11: init %i32 = converted %.loc9_26, %int.convert_checked.loc9_27.2 [template = constants.%.38]
  198. // CHECK:STDOUT: %.loc9_27.12: ref %i32 = class_element_access %return, element1
  199. // CHECK:STDOUT: %.loc9_27.13: init %i32 = initialize_from %.loc9_27.11 to %.loc9_27.12 [template = constants.%.38]
  200. // CHECK:STDOUT: %.loc9_27.14: init %A = class_init (%.loc9_27.7, %.loc9_27.13), %return [template = constants.%struct]
  201. // CHECK:STDOUT: %.loc9_28: init %A = converted %.loc9_27.1, %.loc9_27.14 [template = constants.%struct]
  202. // CHECK:STDOUT: return %.loc9_28 to %return
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: fn @__global_init() {
  206. // CHECK:STDOUT: !entry:
  207. // CHECK:STDOUT: %.loc17_22: Core.IntLiteral = int_value 1 [template = constants.%.6]
  208. // CHECK:STDOUT: %.loc17_30: Core.IntLiteral = int_value 2 [template = constants.%.7]
  209. // CHECK:STDOUT: %.loc17_31.1: %.8 = struct_literal (%.loc17_22, %.loc17_30)
  210. // CHECK:STDOUT: %.loc17_31.2: %Convert.type.2 = interface_witness_access constants.%.32, element0 [template = constants.%Convert.14]
  211. // CHECK:STDOUT: %.loc17_31.3: <bound method> = bound_method %.loc17_22, %.loc17_31.2 [template = constants.%.33]
  212. // CHECK:STDOUT: %.loc17_31.4: <specific function> = specific_function %.loc17_31.3, @Convert.2(constants.%.1) [template = constants.%.34]
  213. // CHECK:STDOUT: %int.convert_checked.loc17_31.1: init %i32 = call %.loc17_31.4(%.loc17_22) [template = constants.%.35]
  214. // CHECK:STDOUT: %.loc17_31.5: init %i32 = converted %.loc17_22, %int.convert_checked.loc17_31.1 [template = constants.%.35]
  215. // CHECK:STDOUT: %.loc17_31.6: ref %i32 = class_element_access file.%a_ref.var, element0
  216. // CHECK:STDOUT: %.loc17_31.7: init %i32 = initialize_from %.loc17_31.5 to %.loc17_31.6 [template = constants.%.35]
  217. // CHECK:STDOUT: %.loc17_31.8: %Convert.type.2 = interface_witness_access constants.%.32, element0 [template = constants.%Convert.14]
  218. // CHECK:STDOUT: %.loc17_31.9: <bound method> = bound_method %.loc17_30, %.loc17_31.8 [template = constants.%.36]
  219. // CHECK:STDOUT: %.loc17_31.10: <specific function> = specific_function %.loc17_31.9, @Convert.2(constants.%.1) [template = constants.%.37]
  220. // CHECK:STDOUT: %int.convert_checked.loc17_31.2: init %i32 = call %.loc17_31.10(%.loc17_30) [template = constants.%.38]
  221. // CHECK:STDOUT: %.loc17_31.11: init %i32 = converted %.loc17_30, %int.convert_checked.loc17_31.2 [template = constants.%.38]
  222. // CHECK:STDOUT: %.loc17_31.12: ref %i32 = class_element_access file.%a_ref.var, element1
  223. // CHECK:STDOUT: %.loc17_31.13: init %i32 = initialize_from %.loc17_31.11 to %.loc17_31.12 [template = constants.%.38]
  224. // CHECK:STDOUT: %.loc17_31.14: init %A = class_init (%.loc17_31.7, %.loc17_31.13), file.%a_ref.var [template = constants.%struct]
  225. // CHECK:STDOUT: %.loc17_32: init %A = converted %.loc17_31.1, %.loc17_31.14 [template = constants.%struct]
  226. // CHECK:STDOUT: assign file.%a_ref.var, %.loc17_32
  227. // CHECK:STDOUT: %a_ref.ref.loc18: ref %A = name_ref a_ref, file.%a_ref
  228. // CHECK:STDOUT: %.loc18: %A = bind_value %a_ref.ref.loc18
  229. // CHECK:STDOUT: %a_val: %A = bind_name a_val, %.loc18
  230. // CHECK:STDOUT: %a_val.ref: %A = name_ref a_val, %a_val
  231. // CHECK:STDOUT: %B.ref.loc21: type = name_ref B, file.%B.decl [template = constants.%B]
  232. // CHECK:STDOUT: %.loc21_22.1: %B = as_compatible %a_val.ref
  233. // CHECK:STDOUT: %.loc21_22.2: %B = converted %a_val.ref, %.loc21_22.1
  234. // CHECK:STDOUT: %b_val: %B = bind_name b_val, %.loc21_22.2
  235. // CHECK:STDOUT: %a_ref.ref.loc22: ref %A = name_ref a_ref, file.%a_ref
  236. // CHECK:STDOUT: %B.ref.loc22: type = name_ref B, file.%B.decl [template = constants.%B]
  237. // CHECK:STDOUT: %.loc22_25.1: ref %B = as_compatible %a_ref.ref.loc22
  238. // CHECK:STDOUT: %.loc22_25.2: ref %B = converted %a_ref.ref.loc22, %.loc22_25.1
  239. // CHECK:STDOUT: %.loc22_17: %.39 = addr_of %.loc22_25.2
  240. // CHECK:STDOUT: %b_ptr: %.39 = bind_name b_ptr, %.loc22_17
  241. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  242. // CHECK:STDOUT: %Make.ref: %Make.type = name_ref Make, @A.%Make.decl [template = constants.%Make]
  243. // CHECK:STDOUT: %.loc24_5: ref %B = splice_block file.%b_factory.var {}
  244. // CHECK:STDOUT: %Make.call: init %A = call %Make.ref() to %.loc24_5
  245. // CHECK:STDOUT: %B.ref.loc24: type = name_ref B, file.%B.decl [template = constants.%B]
  246. // CHECK:STDOUT: %.loc24_29.1: init %B = as_compatible %Make.call
  247. // CHECK:STDOUT: %.loc24_29.2: init %B = converted %Make.call, %.loc24_29.1
  248. // CHECK:STDOUT: assign file.%b_factory.var, %.loc24_29.2
  249. // CHECK:STDOUT: return
  250. // CHECK:STDOUT: }
  251. // CHECK:STDOUT:
  252. // CHECK:STDOUT: --- adapt_i32.carbon
  253. // CHECK:STDOUT:
  254. // CHECK:STDOUT: constants {
  255. // CHECK:STDOUT: %A: type = class_type @A [template]
  256. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  257. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  258. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  259. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  260. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %i32 [template]
  261. // CHECK:STDOUT: %.3: Core.IntLiteral = int_value 1 [template]
  262. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @As(%i32) [template]
  263. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.7, @impl.5(%.1) [template]
  264. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  265. // CHECK:STDOUT: %.27: <witness> = interface_witness (%Convert.14) [template]
  266. // CHECK:STDOUT: %.28: <bound method> = bound_method %.3, %Convert.14 [template]
  267. // CHECK:STDOUT: %.29: <specific function> = specific_function %.28, @Convert.7(%.1) [template]
  268. // CHECK:STDOUT: %.30: %i32 = int_value 1 [template]
  269. // CHECK:STDOUT: }
  270. // CHECK:STDOUT:
  271. // CHECK:STDOUT: imports {
  272. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  273. // CHECK:STDOUT: .Int = %import_ref.1
  274. // CHECK:STDOUT: .As = %import_ref.2
  275. // CHECK:STDOUT: import Core//prelude
  276. // CHECK:STDOUT: import Core//prelude/...
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT: }
  279. // CHECK:STDOUT:
  280. // CHECK:STDOUT: file {
  281. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  282. // CHECK:STDOUT: .Core = imports.%Core
  283. // CHECK:STDOUT: .A = %A.decl
  284. // CHECK:STDOUT: .a = @__global_init.%a
  285. // CHECK:STDOUT: .n = @__global_init.%n
  286. // CHECK:STDOUT: }
  287. // CHECK:STDOUT: %Core.import = import Core
  288. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  289. // CHECK:STDOUT: %A.ref: type = name_ref A, %A.decl [template = constants.%A]
  290. // CHECK:STDOUT: %.loc9_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  291. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc9_8.1) [template = constants.%i32]
  292. // CHECK:STDOUT: %.loc9_8.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  293. // CHECK:STDOUT: %.loc9_8.3: type = converted %int.make_type_signed, %.loc9_8.2 [template = constants.%i32]
  294. // CHECK:STDOUT: }
  295. // CHECK:STDOUT:
  296. // CHECK:STDOUT: class @A {
  297. // CHECK:STDOUT: %.loc5_9: Core.IntLiteral = int_value 32 [template = constants.%.1]
  298. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc5_9) [template = constants.%i32]
  299. // CHECK:STDOUT: %.loc5_12.1: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  300. // CHECK:STDOUT: %.loc5_12.2: type = converted %int.make_type_signed, %.loc5_12.1 [template = constants.%i32]
  301. // CHECK:STDOUT: adapt_decl %.loc5_12.2 [template]
  302. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %i32 [template = constants.%.2]
  303. // CHECK:STDOUT:
  304. // CHECK:STDOUT: !members:
  305. // CHECK:STDOUT: .Self = constants.%A
  306. // CHECK:STDOUT: }
  307. // CHECK:STDOUT:
  308. // CHECK:STDOUT: fn @__global_init() {
  309. // CHECK:STDOUT: !entry:
  310. // CHECK:STDOUT: %.loc8_13: Core.IntLiteral = int_value 1 [template = constants.%.3]
  311. // CHECK:STDOUT: %.loc8_18.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  312. // CHECK:STDOUT: %int.make_type_signed.loc8: init type = call constants.%Int(%.loc8_18.1) [template = constants.%i32]
  313. // CHECK:STDOUT: %.loc8_18.2: type = value_of_initializer %int.make_type_signed.loc8 [template = constants.%i32]
  314. // CHECK:STDOUT: %.loc8_18.3: type = converted %int.make_type_signed.loc8, %.loc8_18.2 [template = constants.%i32]
  315. // CHECK:STDOUT: %.loc8_15.1: %Convert.type.2 = interface_witness_access constants.%.27, element0 [template = constants.%Convert.14]
  316. // CHECK:STDOUT: %.loc8_15.2: <bound method> = bound_method %.loc8_13, %.loc8_15.1 [template = constants.%.28]
  317. // CHECK:STDOUT: %.loc8_15.3: <specific function> = specific_function %.loc8_15.2, @Convert.7(constants.%.1) [template = constants.%.29]
  318. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc8_15.3(%.loc8_13) [template = constants.%.30]
  319. // CHECK:STDOUT: %.loc8_15.4: %i32 = value_of_initializer %int.convert_checked [template = constants.%.30]
  320. // CHECK:STDOUT: %.loc8_15.5: %i32 = converted %.loc8_13, %.loc8_15.4 [template = constants.%.30]
  321. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  322. // CHECK:STDOUT: %.loc8_23.1: %A = as_compatible %.loc8_15.5 [template = constants.%.30]
  323. // CHECK:STDOUT: %.loc8_23.2: %A = converted %.loc8_15.5, %.loc8_23.1 [template = constants.%.30]
  324. // CHECK:STDOUT: %a: %A = bind_name a, %.loc8_23.2
  325. // CHECK:STDOUT: %a.ref: %A = name_ref a, %a
  326. // CHECK:STDOUT: %.loc9_19.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  327. // CHECK:STDOUT: %int.make_type_signed.loc9: init type = call constants.%Int(%.loc9_19.1) [template = constants.%i32]
  328. // CHECK:STDOUT: %.loc9_19.2: type = value_of_initializer %int.make_type_signed.loc9 [template = constants.%i32]
  329. // CHECK:STDOUT: %.loc9_19.3: type = converted %int.make_type_signed.loc9, %.loc9_19.2 [template = constants.%i32]
  330. // CHECK:STDOUT: %.loc9_16.1: %i32 = as_compatible %a.ref
  331. // CHECK:STDOUT: %.loc9_16.2: %i32 = converted %a.ref, %.loc9_16.1
  332. // CHECK:STDOUT: %n: %i32 = bind_name n, %.loc9_16.2
  333. // CHECK:STDOUT: return
  334. // CHECK:STDOUT: }
  335. // CHECK:STDOUT:
  336. // CHECK:STDOUT: --- multi_level_adapt.carbon
  337. // CHECK:STDOUT:
  338. // CHECK:STDOUT: constants {
  339. // CHECK:STDOUT: %A: type = class_type @A [template]
  340. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  341. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  342. // CHECK:STDOUT: %B: type = class_type @B [template]
  343. // CHECK:STDOUT: %C: type = class_type @C [template]
  344. // CHECK:STDOUT: %D: type = class_type @D [template]
  345. // CHECK:STDOUT: %struct: %.1 = struct_value () [template]
  346. // CHECK:STDOUT: }
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: imports {
  349. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  350. // CHECK:STDOUT: import Core//prelude
  351. // CHECK:STDOUT: import Core//prelude/...
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT: }
  354. // CHECK:STDOUT:
  355. // CHECK:STDOUT: file {
  356. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  357. // CHECK:STDOUT: .Core = imports.%Core
  358. // CHECK:STDOUT: .A = %A.decl
  359. // CHECK:STDOUT: .B = %B.decl
  360. // CHECK:STDOUT: .C = %C.decl
  361. // CHECK:STDOUT: .D = %D.decl
  362. // CHECK:STDOUT: .d = @__global_init.%d
  363. // CHECK:STDOUT: }
  364. // CHECK:STDOUT: %Core.import = import Core
  365. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  366. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  367. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  368. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  369. // CHECK:STDOUT: %D.ref: type = name_ref D, %D.decl [template = constants.%D]
  370. // CHECK:STDOUT: }
  371. // CHECK:STDOUT:
  372. // CHECK:STDOUT: class @A {
  373. // CHECK:STDOUT: %.loc4_18: %.1 = struct_literal ()
  374. // CHECK:STDOUT: %.loc4_19: type = converted %.loc4_18, constants.%.1 [template = constants.%.1]
  375. // CHECK:STDOUT: adapt_decl %.loc4_19 [template]
  376. // CHECK:STDOUT: %.loc4_21: <witness> = complete_type_witness %.1 [template = constants.%.2]
  377. // CHECK:STDOUT:
  378. // CHECK:STDOUT: !members:
  379. // CHECK:STDOUT: .Self = constants.%A
  380. // CHECK:STDOUT: }
  381. // CHECK:STDOUT:
  382. // CHECK:STDOUT: class @B {
  383. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  384. // CHECK:STDOUT: adapt_decl %A.ref [template]
  385. // CHECK:STDOUT: %.loc5: <witness> = complete_type_witness %.1 [template = constants.%.2]
  386. // CHECK:STDOUT:
  387. // CHECK:STDOUT: !members:
  388. // CHECK:STDOUT: .Self = constants.%B
  389. // CHECK:STDOUT: }
  390. // CHECK:STDOUT:
  391. // CHECK:STDOUT: class @C {
  392. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  393. // CHECK:STDOUT: adapt_decl %B.ref [template]
  394. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.1 [template = constants.%.2]
  395. // CHECK:STDOUT:
  396. // CHECK:STDOUT: !members:
  397. // CHECK:STDOUT: .Self = constants.%C
  398. // CHECK:STDOUT: }
  399. // CHECK:STDOUT:
  400. // CHECK:STDOUT: class @D {
  401. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  402. // CHECK:STDOUT: adapt_decl %C.ref [template]
  403. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.1 [template = constants.%.2]
  404. // CHECK:STDOUT:
  405. // CHECK:STDOUT: !members:
  406. // CHECK:STDOUT: .Self = constants.%D
  407. // CHECK:STDOUT: }
  408. // CHECK:STDOUT:
  409. // CHECK:STDOUT: fn @__global_init() {
  410. // CHECK:STDOUT: !entry:
  411. // CHECK:STDOUT: %.loc9_13: %.1 = struct_literal ()
  412. // CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [template = constants.%D]
  413. // CHECK:STDOUT: %struct: %.1 = struct_value () [template = constants.%struct]
  414. // CHECK:STDOUT: %.loc9_15.1: %D = as_compatible %struct [template = constants.%struct]
  415. // CHECK:STDOUT: %.loc9_15.2: %D = converted %.loc9_13, %.loc9_15.1 [template = constants.%struct]
  416. // CHECK:STDOUT: %d: %D = bind_name d, %.loc9_15.2
  417. // CHECK:STDOUT: return
  418. // CHECK:STDOUT: }
  419. // CHECK:STDOUT:
  420. // CHECK:STDOUT: --- fail_init_class.carbon
  421. // CHECK:STDOUT:
  422. // CHECK:STDOUT: constants {
  423. // CHECK:STDOUT: %A: type = class_type @A [template]
  424. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  425. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  426. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  427. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  428. // CHECK:STDOUT: %.2: type = unbound_element_type %A, %i32 [template]
  429. // CHECK:STDOUT: %.3: type = struct_type {.x: %i32, .y: %i32} [template]
  430. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  431. // CHECK:STDOUT: %B: type = class_type @B [template]
  432. // CHECK:STDOUT: %.6: Core.IntLiteral = int_value 1 [template]
  433. // CHECK:STDOUT: %.7: Core.IntLiteral = int_value 2 [template]
  434. // CHECK:STDOUT: %.8: type = struct_type {.x: Core.IntLiteral, .y: Core.IntLiteral} [template]
  435. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  436. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  437. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  438. // CHECK:STDOUT: %.32: <witness> = interface_witness (%Convert.14) [template]
  439. // CHECK:STDOUT: %.33: <bound method> = bound_method %.6, %Convert.14 [template]
  440. // CHECK:STDOUT: %.34: <specific function> = specific_function %.33, @Convert.2(%.1) [template]
  441. // CHECK:STDOUT: %.35: %i32 = int_value 1 [template]
  442. // CHECK:STDOUT: %.36: <bound method> = bound_method %.7, %Convert.14 [template]
  443. // CHECK:STDOUT: %.37: <specific function> = specific_function %.36, @Convert.2(%.1) [template]
  444. // CHECK:STDOUT: %.38: %i32 = int_value 2 [template]
  445. // CHECK:STDOUT: %struct: %A = struct_value (%.35, %.38) [template]
  446. // CHECK:STDOUT: }
  447. // CHECK:STDOUT:
  448. // CHECK:STDOUT: imports {
  449. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  450. // CHECK:STDOUT: .Int = %import_ref.1
  451. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  452. // CHECK:STDOUT: import Core//prelude
  453. // CHECK:STDOUT: import Core//prelude/...
  454. // CHECK:STDOUT: }
  455. // CHECK:STDOUT: }
  456. // CHECK:STDOUT:
  457. // CHECK:STDOUT: file {
  458. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  459. // CHECK:STDOUT: .Core = imports.%Core
  460. // CHECK:STDOUT: .A = %A.decl
  461. // CHECK:STDOUT: .B = %B.decl
  462. // CHECK:STDOUT: .b_value = @__global_init.%b_value
  463. // CHECK:STDOUT: .b_init = %b_init
  464. // CHECK:STDOUT: }
  465. // CHECK:STDOUT: %Core.import = import Core
  466. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  467. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  468. // CHECK:STDOUT: %B.ref.loc13: type = name_ref B, %B.decl [template = constants.%B]
  469. // CHECK:STDOUT: %B.ref.loc24: type = name_ref B, %B.decl [template = constants.%B]
  470. // CHECK:STDOUT: %b_init.var: ref %B = var b_init
  471. // CHECK:STDOUT: %b_init: ref %B = bind_name b_init, %b_init.var
  472. // CHECK:STDOUT: }
  473. // CHECK:STDOUT:
  474. // CHECK:STDOUT: class @A {
  475. // CHECK:STDOUT: %.loc5_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  476. // CHECK:STDOUT: %int.make_type_signed.loc5: init type = call constants.%Int(%.loc5_10.1) [template = constants.%i32]
  477. // CHECK:STDOUT: %.loc5_10.2: type = value_of_initializer %int.make_type_signed.loc5 [template = constants.%i32]
  478. // CHECK:STDOUT: %.loc5_10.3: type = converted %int.make_type_signed.loc5, %.loc5_10.2 [template = constants.%i32]
  479. // CHECK:STDOUT: %.loc5_8: %.2 = field_decl x, element0 [template]
  480. // CHECK:STDOUT: %.loc6_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  481. // CHECK:STDOUT: %int.make_type_signed.loc6: init type = call constants.%Int(%.loc6_10.1) [template = constants.%i32]
  482. // CHECK:STDOUT: %.loc6_10.2: type = value_of_initializer %int.make_type_signed.loc6 [template = constants.%i32]
  483. // CHECK:STDOUT: %.loc6_10.3: type = converted %int.make_type_signed.loc6, %.loc6_10.2 [template = constants.%i32]
  484. // CHECK:STDOUT: %.loc6_8: %.2 = field_decl y, element1 [template]
  485. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.3 [template = constants.%.4]
  486. // CHECK:STDOUT:
  487. // CHECK:STDOUT: !members:
  488. // CHECK:STDOUT: .Self = constants.%A
  489. // CHECK:STDOUT: .x = %.loc5_8
  490. // CHECK:STDOUT: .y = %.loc6_8
  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: adapt_decl %A.ref [template]
  496. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %.3 [template = constants.%.4]
  497. // CHECK:STDOUT:
  498. // CHECK:STDOUT: !members:
  499. // CHECK:STDOUT: .Self = constants.%B
  500. // CHECK:STDOUT: }
  501. // CHECK:STDOUT:
  502. // CHECK:STDOUT: fn @__global_init() {
  503. // CHECK:STDOUT: !entry:
  504. // CHECK:STDOUT: %.loc13_25: Core.IntLiteral = int_value 1 [template = constants.%.6]
  505. // CHECK:STDOUT: %.loc13_33: Core.IntLiteral = int_value 2 [template = constants.%.7]
  506. // CHECK:STDOUT: %.loc13_34.1: %.8 = struct_literal (%.loc13_25, %.loc13_33)
  507. // CHECK:STDOUT: %A.ref.loc13: type = name_ref A, file.%A.decl [template = constants.%A]
  508. // CHECK:STDOUT: %.loc13_34.2: %Convert.type.2 = interface_witness_access constants.%.32, element0 [template = constants.%Convert.14]
  509. // CHECK:STDOUT: %.loc13_34.3: <bound method> = bound_method %.loc13_25, %.loc13_34.2 [template = constants.%.33]
  510. // CHECK:STDOUT: %.loc13_34.4: <specific function> = specific_function %.loc13_34.3, @Convert.2(constants.%.1) [template = constants.%.34]
  511. // CHECK:STDOUT: %int.convert_checked.loc13_34.1: init %i32 = call %.loc13_34.4(%.loc13_25) [template = constants.%.35]
  512. // CHECK:STDOUT: %.loc13_34.5: init %i32 = converted %.loc13_25, %int.convert_checked.loc13_34.1 [template = constants.%.35]
  513. // CHECK:STDOUT: %.loc13_34.6: ref %A = temporary_storage
  514. // CHECK:STDOUT: %.loc13_34.7: ref %i32 = class_element_access %.loc13_34.6, element0
  515. // CHECK:STDOUT: %.loc13_34.8: init %i32 = initialize_from %.loc13_34.5 to %.loc13_34.7 [template = constants.%.35]
  516. // CHECK:STDOUT: %.loc13_34.9: %Convert.type.2 = interface_witness_access constants.%.32, element0 [template = constants.%Convert.14]
  517. // CHECK:STDOUT: %.loc13_34.10: <bound method> = bound_method %.loc13_33, %.loc13_34.9 [template = constants.%.36]
  518. // CHECK:STDOUT: %.loc13_34.11: <specific function> = specific_function %.loc13_34.10, @Convert.2(constants.%.1) [template = constants.%.37]
  519. // CHECK:STDOUT: %int.convert_checked.loc13_34.2: init %i32 = call %.loc13_34.11(%.loc13_33) [template = constants.%.38]
  520. // CHECK:STDOUT: %.loc13_34.12: init %i32 = converted %.loc13_33, %int.convert_checked.loc13_34.2 [template = constants.%.38]
  521. // CHECK:STDOUT: %.loc13_34.13: ref %i32 = class_element_access %.loc13_34.6, element1
  522. // CHECK:STDOUT: %.loc13_34.14: init %i32 = initialize_from %.loc13_34.12 to %.loc13_34.13 [template = constants.%.38]
  523. // CHECK:STDOUT: %.loc13_34.15: init %A = class_init (%.loc13_34.8, %.loc13_34.14), %.loc13_34.6 [template = constants.%struct]
  524. // CHECK:STDOUT: %.loc13_34.16: ref %A = temporary %.loc13_34.6, %.loc13_34.15
  525. // CHECK:STDOUT: %.loc13_36: ref %A = converted %.loc13_34.1, %.loc13_34.16
  526. // CHECK:STDOUT: %B.ref.loc13: type = name_ref B, file.%B.decl [template = constants.%B]
  527. // CHECK:STDOUT: %.loc13_42.1: ref %B = as_compatible %.loc13_36
  528. // CHECK:STDOUT: %.loc13_42.2: ref %B = converted %.loc13_36, %.loc13_42.1
  529. // CHECK:STDOUT: %.loc13_42.3: %B = bind_value %.loc13_42.2
  530. // CHECK:STDOUT: %b_value: %B = bind_name b_value, %.loc13_42.3
  531. // CHECK:STDOUT: %.loc24_24: Core.IntLiteral = int_value 1 [template = constants.%.6]
  532. // CHECK:STDOUT: %.loc24_32: Core.IntLiteral = int_value 2 [template = constants.%.7]
  533. // CHECK:STDOUT: %.loc24_33.1: %.8 = struct_literal (%.loc24_24, %.loc24_32)
  534. // CHECK:STDOUT: %A.ref.loc24: type = name_ref A, file.%A.decl [template = constants.%A]
  535. // CHECK:STDOUT: %.loc24_33.2: %Convert.type.2 = interface_witness_access constants.%.32, element0 [template = constants.%Convert.14]
  536. // CHECK:STDOUT: %.loc24_33.3: <bound method> = bound_method %.loc24_24, %.loc24_33.2 [template = constants.%.33]
  537. // CHECK:STDOUT: %.loc24_33.4: <specific function> = specific_function %.loc24_33.3, @Convert.2(constants.%.1) [template = constants.%.34]
  538. // CHECK:STDOUT: %int.convert_checked.loc24_33.1: init %i32 = call %.loc24_33.4(%.loc24_24) [template = constants.%.35]
  539. // CHECK:STDOUT: %.loc24_33.5: init %i32 = converted %.loc24_24, %int.convert_checked.loc24_33.1 [template = constants.%.35]
  540. // CHECK:STDOUT: %.loc24_33.6: ref %A = temporary_storage
  541. // CHECK:STDOUT: %.loc24_33.7: ref %i32 = class_element_access %.loc24_33.6, element0
  542. // CHECK:STDOUT: %.loc24_33.8: init %i32 = initialize_from %.loc24_33.5 to %.loc24_33.7 [template = constants.%.35]
  543. // CHECK:STDOUT: %.loc24_33.9: %Convert.type.2 = interface_witness_access constants.%.32, element0 [template = constants.%Convert.14]
  544. // CHECK:STDOUT: %.loc24_33.10: <bound method> = bound_method %.loc24_32, %.loc24_33.9 [template = constants.%.36]
  545. // CHECK:STDOUT: %.loc24_33.11: <specific function> = specific_function %.loc24_33.10, @Convert.2(constants.%.1) [template = constants.%.37]
  546. // CHECK:STDOUT: %int.convert_checked.loc24_33.2: init %i32 = call %.loc24_33.11(%.loc24_32) [template = constants.%.38]
  547. // CHECK:STDOUT: %.loc24_33.12: init %i32 = converted %.loc24_32, %int.convert_checked.loc24_33.2 [template = constants.%.38]
  548. // CHECK:STDOUT: %.loc24_33.13: ref %i32 = class_element_access %.loc24_33.6, element1
  549. // CHECK:STDOUT: %.loc24_33.14: init %i32 = initialize_from %.loc24_33.12 to %.loc24_33.13 [template = constants.%.38]
  550. // CHECK:STDOUT: %.loc24_33.15: init %A = class_init (%.loc24_33.8, %.loc24_33.14), %.loc24_33.6 [template = constants.%struct]
  551. // CHECK:STDOUT: %.loc24_33.16: ref %A = temporary %.loc24_33.6, %.loc24_33.15
  552. // CHECK:STDOUT: %.loc24_35: ref %A = converted %.loc24_33.1, %.loc24_33.16
  553. // CHECK:STDOUT: %B.ref.loc24: type = name_ref B, file.%B.decl [template = constants.%B]
  554. // CHECK:STDOUT: %.loc24_41.1: ref %B = as_compatible %.loc24_35
  555. // CHECK:STDOUT: %.loc24_41.2: ref %B = converted %.loc24_35, %.loc24_41.1
  556. // CHECK:STDOUT: %.loc24_41.3: %B = bind_value %.loc24_41.2
  557. // CHECK:STDOUT: assign file.%b_init.var, <error>
  558. // CHECK:STDOUT: return
  559. // CHECK:STDOUT: }
  560. // CHECK:STDOUT:
  561. // CHECK:STDOUT: --- fail_adapt_init_from_struct.carbon
  562. // CHECK:STDOUT:
  563. // CHECK:STDOUT: constants {
  564. // CHECK:STDOUT: %A: type = class_type @A [template]
  565. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  566. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  567. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  568. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  569. // CHECK:STDOUT: %.2: type = unbound_element_type %A, %i32 [template]
  570. // CHECK:STDOUT: %.3: type = struct_type {.x: %i32} [template]
  571. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  572. // CHECK:STDOUT: %B: type = class_type @B [template]
  573. // CHECK:STDOUT: %.6: Core.IntLiteral = int_value 1 [template]
  574. // CHECK:STDOUT: %.7: type = struct_type {.x: Core.IntLiteral} [template]
  575. // CHECK:STDOUT: }
  576. // CHECK:STDOUT:
  577. // CHECK:STDOUT: imports {
  578. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  579. // CHECK:STDOUT: .Int = %import_ref.1
  580. // CHECK:STDOUT: .As = %import_ref.2
  581. // CHECK:STDOUT: import Core//prelude
  582. // CHECK:STDOUT: import Core//prelude/...
  583. // CHECK:STDOUT: }
  584. // CHECK:STDOUT: }
  585. // CHECK:STDOUT:
  586. // CHECK:STDOUT: file {
  587. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  588. // CHECK:STDOUT: .Core = imports.%Core
  589. // CHECK:STDOUT: .A = %A.decl
  590. // CHECK:STDOUT: .B = %B.decl
  591. // CHECK:STDOUT: .b = %b
  592. // CHECK:STDOUT: }
  593. // CHECK:STDOUT: %Core.import = import Core
  594. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  595. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  596. // CHECK:STDOUT: %B.ref: type = name_ref B, %B.decl [template = constants.%B]
  597. // CHECK:STDOUT: %b.var: ref %B = var b
  598. // CHECK:STDOUT: %b: ref %B = bind_name b, %b.var
  599. // CHECK:STDOUT: }
  600. // CHECK:STDOUT:
  601. // CHECK:STDOUT: class @A {
  602. // CHECK:STDOUT: %.loc5_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  603. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc5_10.1) [template = constants.%i32]
  604. // CHECK:STDOUT: %.loc5_10.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  605. // CHECK:STDOUT: %.loc5_10.3: type = converted %int.make_type_signed, %.loc5_10.2 [template = constants.%i32]
  606. // CHECK:STDOUT: %.loc5_8: %.2 = field_decl x, element0 [template]
  607. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.3 [template = constants.%.4]
  608. // CHECK:STDOUT:
  609. // CHECK:STDOUT: !members:
  610. // CHECK:STDOUT: .Self = constants.%A
  611. // CHECK:STDOUT: .x = %.loc5_8
  612. // CHECK:STDOUT: }
  613. // CHECK:STDOUT:
  614. // CHECK:STDOUT: class @B {
  615. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  616. // CHECK:STDOUT: adapt_decl %A.ref [template]
  617. // CHECK:STDOUT: %.loc10: <witness> = complete_type_witness %.3 [template = constants.%.4]
  618. // CHECK:STDOUT:
  619. // CHECK:STDOUT: !members:
  620. // CHECK:STDOUT: .Self = constants.%B
  621. // CHECK:STDOUT: }
  622. // CHECK:STDOUT:
  623. // CHECK:STDOUT: fn @__global_init() {
  624. // CHECK:STDOUT: !entry:
  625. // CHECK:STDOUT: %.loc21_18: Core.IntLiteral = int_value 1 [template = constants.%.6]
  626. // CHECK:STDOUT: %.loc21_19: %.7 = struct_literal (%.loc21_18)
  627. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  628. // CHECK:STDOUT: %.loc21_21: %B = converted %.loc21_19, <error> [template = <error>]
  629. // CHECK:STDOUT: assign file.%b.var, <error>
  630. // CHECK:STDOUT: return
  631. // CHECK:STDOUT: }
  632. // CHECK:STDOUT: