fail_impl_as_scope.carbon 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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. // INCLUDE-FILE: toolchain/testing/min_prelude/destroy.carbon
  6. // EXTRA-ARGS: --custom-core
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/min_prelude/fail_impl_as_scope.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/min_prelude/fail_impl_as_scope.carbon
  13. // --- fail_impl_as_file_scope.carbon
  14. library "[[@TEST_NAME]]";
  15. interface I {}
  16. fn G() {}
  17. // CHECK:STDERR: fail_impl_as_file_scope.carbon:[[@LINE+4]]:6: error: `impl as` can only be used in a class [ImplAsOutsideClass]
  18. // CHECK:STDERR: impl as I {}
  19. // CHECK:STDERR: ^~
  20. // CHECK:STDERR:
  21. impl as I {}
  22. fn F() { G(); }
  23. // --- fail_impl_as_function_scope.carbon
  24. library "[[@TEST_NAME]]";
  25. interface J {}
  26. fn G() {}
  27. fn F() {
  28. // CHECK:STDERR: fail_impl_as_function_scope.carbon:[[@LINE+4]]:8: error: `impl as` can only be used in a class [ImplAsOutsideClass]
  29. // CHECK:STDERR: impl as J {}
  30. // CHECK:STDERR: ^~
  31. // CHECK:STDERR:
  32. impl as J {}
  33. G();
  34. }
  35. // --- fail_impl_as_self_interface.carbon
  36. library "[[@TEST_NAME]]";
  37. interface Z {
  38. fn Zero();
  39. fn Method[self: Self]();
  40. // CHECK:STDERR: fail_impl_as_self_interface.carbon:[[@LINE+4]]:9: error: `impl as` can only be used in a class [ImplAsOutsideClass]
  41. // CHECK:STDERR: impl as Z {
  42. // CHECK:STDERR: ^~
  43. // CHECK:STDERR:
  44. impl as Z {
  45. fn Zero() {}
  46. fn Method[self: Self]() {}
  47. }
  48. }
  49. class Point {
  50. impl as Z {
  51. fn Zero() {}
  52. fn Method[self: Self]() {}
  53. }
  54. }
  55. fn F() {
  56. // Even if the `impl` is diagnosed above, we must not add the impl of the
  57. // interface to itself in a way that allows it to be used during impl lookup,
  58. // or we end up with infinite impl lookup recursion here.
  59. Point.(Z.Zero)();
  60. ({} as Point).(Z.Method)();
  61. }
  62. // --- fail_impl_as_other_interface.carbon
  63. library "[[@TEST_NAME]]";
  64. interface A {
  65. fn B();
  66. }
  67. interface C {}
  68. fn G() {}
  69. class X {
  70. impl as A {
  71. // CHECK:STDERR: fail_impl_as_other_interface.carbon:[[@LINE+4]]:10: error: `impl as` can only be used in a class [ImplAsOutsideClass]
  72. // CHECK:STDERR: impl as C {}
  73. // CHECK:STDERR: ^~
  74. // CHECK:STDERR:
  75. impl as C {}
  76. fn B() {
  77. G();
  78. }
  79. }
  80. }
  81. // CHECK:STDOUT: --- fail_impl_as_file_scope.carbon
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: constants {
  84. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  85. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  86. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  87. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  88. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  89. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  90. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: imports {
  94. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  95. // CHECK:STDOUT: import Core//prelude
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: file {
  100. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  101. // CHECK:STDOUT: .Core = imports.%Core
  102. // CHECK:STDOUT: .I = %I.decl
  103. // CHECK:STDOUT: .G = %G.decl
  104. // CHECK:STDOUT: .F = %F.decl
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %Core.import = import Core
  107. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  108. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  109. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  110. // CHECK:STDOUT: %Self.ref: type = name_ref Self, <error> [concrete = <error>]
  111. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: interface @I {
  117. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: !members:
  120. // CHECK:STDOUT: .Self = %Self
  121. // CHECK:STDOUT: witness = ()
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: impl @impl: %Self.ref as %I.ref {
  125. // CHECK:STDOUT: !members:
  126. // CHECK:STDOUT: witness = <error>
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: fn @G() {
  130. // CHECK:STDOUT: !entry:
  131. // CHECK:STDOUT: return
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: fn @F() {
  135. // CHECK:STDOUT: !entry:
  136. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
  137. // CHECK:STDOUT: %G.call: init %empty_tuple.type = call %G.ref()
  138. // CHECK:STDOUT: return
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: --- fail_impl_as_function_scope.carbon
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: constants {
  144. // CHECK:STDOUT: %J.type: type = facet_type <@J> [concrete]
  145. // CHECK:STDOUT: %Self: %J.type = bind_symbolic_name Self, 0 [symbolic]
  146. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  147. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  148. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  149. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  150. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: imports {
  154. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  155. // CHECK:STDOUT: import Core//prelude
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: file {
  160. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  161. // CHECK:STDOUT: .Core = imports.%Core
  162. // CHECK:STDOUT: .J = %J.decl
  163. // CHECK:STDOUT: .G = %G.decl
  164. // CHECK:STDOUT: .F = %F.decl
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT: %Core.import = import Core
  167. // CHECK:STDOUT: %J.decl: type = interface_decl @J [concrete = constants.%J.type] {} {}
  168. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  169. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: interface @J {
  173. // CHECK:STDOUT: %Self: %J.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: !members:
  176. // CHECK:STDOUT: .Self = %Self
  177. // CHECK:STDOUT: witness = ()
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: impl @impl: %Self.ref as %J.ref {
  181. // CHECK:STDOUT: !members:
  182. // CHECK:STDOUT: witness = <error>
  183. // CHECK:STDOUT: }
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: fn @G() {
  186. // CHECK:STDOUT: !entry:
  187. // CHECK:STDOUT: return
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: fn @F() {
  191. // CHECK:STDOUT: !entry:
  192. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  193. // CHECK:STDOUT: %Self.ref: type = name_ref Self, <error> [concrete = <error>]
  194. // CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [concrete = constants.%J.type]
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
  197. // CHECK:STDOUT: %G.call: init %empty_tuple.type = call %G.ref()
  198. // CHECK:STDOUT: return
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: --- fail_impl_as_self_interface.carbon
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: constants {
  204. // CHECK:STDOUT: %Z.type: type = facet_type <@Z> [concrete]
  205. // CHECK:STDOUT: %Self: %Z.type = bind_symbolic_name Self, 0 [symbolic]
  206. // CHECK:STDOUT: %Zero.type.822: type = fn_type @Zero.1 [concrete]
  207. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  208. // CHECK:STDOUT: %Zero.d14: %Zero.type.822 = struct_value () [concrete]
  209. // CHECK:STDOUT: %Z.assoc_type: type = assoc_entity_type @Z [concrete]
  210. // CHECK:STDOUT: %assoc0: %Z.assoc_type = assoc_entity element0, @Z.%Zero.decl [concrete]
  211. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self [symbolic]
  212. // CHECK:STDOUT: %pattern_type.a40: type = pattern_type %Self.as_type [symbolic]
  213. // CHECK:STDOUT: %Method.type.f12: type = fn_type @Method.1 [concrete]
  214. // CHECK:STDOUT: %Method.724: %Method.type.f12 = struct_value () [concrete]
  215. // CHECK:STDOUT: %assoc1: %Z.assoc_type = assoc_entity element1, @Z.%Method.decl [concrete]
  216. // CHECK:STDOUT: %Zero.type.db4: type = fn_type @Zero.2, @impl.6b5(%Self) [symbolic]
  217. // CHECK:STDOUT: %Zero.8fb: %Zero.type.db4 = struct_value () [symbolic]
  218. // CHECK:STDOUT: %Method.type.163: type = fn_type @Method.2, @impl.6b5(%Self) [symbolic]
  219. // CHECK:STDOUT: %Method.84d: %Method.type.163 = struct_value () [symbolic]
  220. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %Self.as_type [symbolic]
  221. // CHECK:STDOUT: %Point: type = class_type @Point [concrete]
  222. // CHECK:STDOUT: %Z.impl_witness: <witness> = impl_witness @Point.%Z.impl_witness_table [concrete]
  223. // CHECK:STDOUT: %Zero.type.e33: type = fn_type @Zero.3 [concrete]
  224. // CHECK:STDOUT: %Zero.dec: %Zero.type.e33 = struct_value () [concrete]
  225. // CHECK:STDOUT: %pattern_type.35b: type = pattern_type %Point [concrete]
  226. // CHECK:STDOUT: %Method.type.2ed: type = fn_type @Method.3 [concrete]
  227. // CHECK:STDOUT: %Method.2c2: %Method.type.2ed = struct_value () [concrete]
  228. // CHECK:STDOUT: %Z.facet: %Z.type = facet_value %Point, (%Z.impl_witness) [concrete]
  229. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  230. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  231. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  232. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  233. // CHECK:STDOUT: %.d52: type = fn_type_with_self_type %Zero.type.822, %Z.facet [concrete]
  234. // CHECK:STDOUT: %Point.val: %Point = struct_value () [concrete]
  235. // CHECK:STDOUT: %.462: type = fn_type_with_self_type %Method.type.f12, %Z.facet [concrete]
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT:
  238. // CHECK:STDOUT: imports {
  239. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  240. // CHECK:STDOUT: import Core//prelude
  241. // CHECK:STDOUT: }
  242. // CHECK:STDOUT: }
  243. // CHECK:STDOUT:
  244. // CHECK:STDOUT: file {
  245. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  246. // CHECK:STDOUT: .Core = imports.%Core
  247. // CHECK:STDOUT: .Z = %Z.decl
  248. // CHECK:STDOUT: .Point = %Point.decl
  249. // CHECK:STDOUT: .F = %F.decl
  250. // CHECK:STDOUT: }
  251. // CHECK:STDOUT: %Core.import = import Core
  252. // CHECK:STDOUT: %Z.decl: type = interface_decl @Z [concrete = constants.%Z.type] {} {}
  253. // CHECK:STDOUT: %Point.decl: type = class_decl @Point [concrete = constants.%Point] {} {}
  254. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  255. // CHECK:STDOUT: }
  256. // CHECK:STDOUT:
  257. // CHECK:STDOUT: interface @Z {
  258. // CHECK:STDOUT: %Self: %Z.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  259. // CHECK:STDOUT: %Zero.decl: %Zero.type.822 = fn_decl @Zero.1 [concrete = constants.%Zero.d14] {} {}
  260. // CHECK:STDOUT: %assoc0: %Z.assoc_type = assoc_entity element0, %Zero.decl [concrete = constants.%assoc0]
  261. // CHECK:STDOUT: %Method.decl: %Method.type.f12 = fn_decl @Method.1 [concrete = constants.%Method.724] {
  262. // CHECK:STDOUT: %self.patt: @Method.1.%pattern_type (%pattern_type.a40) = binding_pattern self
  263. // CHECK:STDOUT: %self.param_patt: @Method.1.%pattern_type (%pattern_type.a40) = value_param_pattern %self.patt, call_param0
  264. // CHECK:STDOUT: } {
  265. // CHECK:STDOUT: %self.param: @Method.1.%Self.as_type.loc5_19.1 (%Self.as_type) = value_param call_param0
  266. // CHECK:STDOUT: %.loc5_19.1: type = splice_block %.loc5_19.2 [symbolic = %Self.as_type.loc5_19.1 (constants.%Self.as_type)] {
  267. // CHECK:STDOUT: %Self.ref: %Z.type = name_ref Self, @Z.%Self [symbolic = %Self (constants.%Self)]
  268. // CHECK:STDOUT: %Self.as_type.loc5_19.2: type = facet_access_type %Self.ref [symbolic = %Self.as_type.loc5_19.1 (constants.%Self.as_type)]
  269. // CHECK:STDOUT: %.loc5_19.2: type = converted %Self.ref, %Self.as_type.loc5_19.2 [symbolic = %Self.as_type.loc5_19.1 (constants.%Self.as_type)]
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT: %self: @Method.1.%Self.as_type.loc5_19.1 (%Self.as_type) = bind_name self, %self.param
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT: %assoc1: %Z.assoc_type = assoc_entity element1, %Method.decl [concrete = constants.%assoc1]
  274. // CHECK:STDOUT: impl_decl @impl.6b5 [concrete] {} {
  275. // CHECK:STDOUT: %Self.ref: type = name_ref Self, <error> [concrete = <error>]
  276. // CHECK:STDOUT: %Z.ref: type = name_ref Z, file.%Z.decl [concrete = constants.%Z.type]
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT:
  279. // CHECK:STDOUT: !members:
  280. // CHECK:STDOUT: .Self = %Self
  281. // CHECK:STDOUT: .Zero = %assoc0
  282. // CHECK:STDOUT: .Method = %assoc1
  283. // CHECK:STDOUT: .Z = <poisoned>
  284. // CHECK:STDOUT: witness = (%Zero.decl, %Method.decl)
  285. // CHECK:STDOUT: }
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: generic impl @impl.6b5(@Z.%Self: %Z.type) {
  288. // CHECK:STDOUT: !definition:
  289. // CHECK:STDOUT: %Self: %Z.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
  290. // CHECK:STDOUT: %Zero.type: type = fn_type @Zero.2, @impl.6b5(%Self) [symbolic = %Zero.type (constants.%Zero.type.db4)]
  291. // CHECK:STDOUT: %Zero: @impl.6b5.%Zero.type (%Zero.type.db4) = struct_value () [symbolic = %Zero (constants.%Zero.8fb)]
  292. // CHECK:STDOUT: %Method.type: type = fn_type @Method.2, @impl.6b5(%Self) [symbolic = %Method.type (constants.%Method.type.163)]
  293. // CHECK:STDOUT: %Method: @impl.6b5.%Method.type (%Method.type.163) = struct_value () [symbolic = %Method (constants.%Method.84d)]
  294. // CHECK:STDOUT:
  295. // CHECK:STDOUT: impl: %Self.ref as %Z.ref {
  296. // CHECK:STDOUT: %Zero.decl: @impl.6b5.%Zero.type (%Zero.type.db4) = fn_decl @Zero.2 [symbolic = @impl.6b5.%Zero (constants.%Zero.8fb)] {} {}
  297. // CHECK:STDOUT: %Method.decl: @impl.6b5.%Method.type (%Method.type.163) = fn_decl @Method.2 [symbolic = @impl.6b5.%Method (constants.%Method.84d)] {
  298. // CHECK:STDOUT: %self.patt: @Method.2.%pattern_type (%pattern_type.a40) = binding_pattern self
  299. // CHECK:STDOUT: %self.param_patt: @Method.2.%pattern_type (%pattern_type.a40) = value_param_pattern %self.patt, call_param0
  300. // CHECK:STDOUT: } {
  301. // CHECK:STDOUT: %self.param: @Method.2.%Self.as_type.loc13_21.1 (%Self.as_type) = value_param call_param0
  302. // CHECK:STDOUT: %.loc13_21.1: type = splice_block %.loc13_21.2 [symbolic = %Self.as_type.loc13_21.1 (constants.%Self.as_type)] {
  303. // CHECK:STDOUT: %Self.ref: %Z.type = name_ref Self, @Z.%Self [symbolic = %Self (constants.%Self)]
  304. // CHECK:STDOUT: %Self.as_type.loc13_21.2: type = facet_access_type %Self.ref [symbolic = %Self.as_type.loc13_21.1 (constants.%Self.as_type)]
  305. // CHECK:STDOUT: %.loc13_21.2: type = converted %Self.ref, %Self.as_type.loc13_21.2 [symbolic = %Self.as_type.loc13_21.1 (constants.%Self.as_type)]
  306. // CHECK:STDOUT: }
  307. // CHECK:STDOUT: %self: @Method.2.%Self.as_type.loc13_21.1 (%Self.as_type) = bind_name self, %self.param
  308. // CHECK:STDOUT: }
  309. // CHECK:STDOUT:
  310. // CHECK:STDOUT: !members:
  311. // CHECK:STDOUT: .Zero = %Zero.decl
  312. // CHECK:STDOUT: .Method = %Method.decl
  313. // CHECK:STDOUT: witness = <error>
  314. // CHECK:STDOUT: }
  315. // CHECK:STDOUT: }
  316. // CHECK:STDOUT:
  317. // CHECK:STDOUT: impl @impl.c94: %Self.ref as %Z.ref {
  318. // CHECK:STDOUT: %Zero.decl: %Zero.type.e33 = fn_decl @Zero.3 [concrete = constants.%Zero.dec] {} {}
  319. // CHECK:STDOUT: %Method.decl: %Method.type.2ed = fn_decl @Method.3 [concrete = constants.%Method.2c2] {
  320. // CHECK:STDOUT: %self.patt: %pattern_type.35b = binding_pattern self
  321. // CHECK:STDOUT: %self.param_patt: %pattern_type.35b = value_param_pattern %self.patt, call_param0
  322. // CHECK:STDOUT: } {
  323. // CHECK:STDOUT: %self.param: %Point = value_param call_param0
  324. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Point [concrete = constants.%Point]
  325. // CHECK:STDOUT: %self: %Point = bind_name self, %self.param
  326. // CHECK:STDOUT: }
  327. // CHECK:STDOUT:
  328. // CHECK:STDOUT: !members:
  329. // CHECK:STDOUT: .Zero = %Zero.decl
  330. // CHECK:STDOUT: .Method = %Method.decl
  331. // CHECK:STDOUT: witness = @Point.%Z.impl_witness
  332. // CHECK:STDOUT: }
  333. // CHECK:STDOUT:
  334. // CHECK:STDOUT: class @Point {
  335. // CHECK:STDOUT: impl_decl @impl.c94 [concrete] {} {
  336. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Point [concrete = constants.%Point]
  337. // CHECK:STDOUT: %Z.ref: type = name_ref Z, file.%Z.decl [concrete = constants.%Z.type]
  338. // CHECK:STDOUT: }
  339. // CHECK:STDOUT: %Z.impl_witness_table = impl_witness_table (@impl.c94.%Zero.decl, @impl.c94.%Method.decl), @impl.c94 [concrete]
  340. // CHECK:STDOUT: %Z.impl_witness: <witness> = impl_witness %Z.impl_witness_table [concrete = constants.%Z.impl_witness]
  341. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  342. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  343. // CHECK:STDOUT: complete_type_witness = %complete_type
  344. // CHECK:STDOUT:
  345. // CHECK:STDOUT: !members:
  346. // CHECK:STDOUT: .Self = constants.%Point
  347. // CHECK:STDOUT: .Z = <poisoned>
  348. // CHECK:STDOUT: }
  349. // CHECK:STDOUT:
  350. // CHECK:STDOUT: generic fn @Zero.1(@Z.%Self: %Z.type) {
  351. // CHECK:STDOUT: fn();
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: generic fn @Method.1(@Z.%Self: %Z.type) {
  355. // CHECK:STDOUT: %Self: %Z.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
  356. // CHECK:STDOUT: %Self.as_type.loc5_19.1: type = facet_access_type %Self [symbolic = %Self.as_type.loc5_19.1 (constants.%Self.as_type)]
  357. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type.loc5_19.1 [symbolic = %pattern_type (constants.%pattern_type.a40)]
  358. // CHECK:STDOUT:
  359. // CHECK:STDOUT: fn(%self.param: @Method.1.%Self.as_type.loc5_19.1 (%Self.as_type));
  360. // CHECK:STDOUT: }
  361. // CHECK:STDOUT:
  362. // CHECK:STDOUT: generic fn @Zero.2(@Z.%Self: %Z.type) {
  363. // CHECK:STDOUT: !definition:
  364. // CHECK:STDOUT:
  365. // CHECK:STDOUT: fn() {
  366. // CHECK:STDOUT: !entry:
  367. // CHECK:STDOUT: return
  368. // CHECK:STDOUT: }
  369. // CHECK:STDOUT: }
  370. // CHECK:STDOUT:
  371. // CHECK:STDOUT: generic fn @Method.2(@Z.%Self: %Z.type) {
  372. // CHECK:STDOUT: %Self: %Z.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
  373. // CHECK:STDOUT: %Self.as_type.loc13_21.1: type = facet_access_type %Self [symbolic = %Self.as_type.loc13_21.1 (constants.%Self.as_type)]
  374. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type.loc13_21.1 [symbolic = %pattern_type (constants.%pattern_type.a40)]
  375. // CHECK:STDOUT:
  376. // CHECK:STDOUT: !definition:
  377. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %Self.as_type.loc13_21.1 [symbolic = %require_complete (constants.%require_complete)]
  378. // CHECK:STDOUT:
  379. // CHECK:STDOUT: fn(%self.param: @Method.2.%Self.as_type.loc13_21.1 (%Self.as_type)) {
  380. // CHECK:STDOUT: !entry:
  381. // CHECK:STDOUT: return
  382. // CHECK:STDOUT: }
  383. // CHECK:STDOUT: }
  384. // CHECK:STDOUT:
  385. // CHECK:STDOUT: fn @Zero.3() {
  386. // CHECK:STDOUT: !entry:
  387. // CHECK:STDOUT: return
  388. // CHECK:STDOUT: }
  389. // CHECK:STDOUT:
  390. // CHECK:STDOUT: fn @Method.3(%self.param: %Point) {
  391. // CHECK:STDOUT: !entry:
  392. // CHECK:STDOUT: return
  393. // CHECK:STDOUT: }
  394. // CHECK:STDOUT:
  395. // CHECK:STDOUT: fn @F() {
  396. // CHECK:STDOUT: !entry:
  397. // CHECK:STDOUT: %Point.ref.loc28: type = name_ref Point, file.%Point.decl [concrete = constants.%Point]
  398. // CHECK:STDOUT: %Z.ref.loc28: type = name_ref Z, file.%Z.decl [concrete = constants.%Z.type]
  399. // CHECK:STDOUT: %Zero.ref: %Z.assoc_type = name_ref Zero, @Z.%assoc0 [concrete = constants.%assoc0]
  400. // CHECK:STDOUT: %Z.facet: %Z.type = facet_value constants.%Point, (constants.%Z.impl_witness) [concrete = constants.%Z.facet]
  401. // CHECK:STDOUT: %.loc28: %Z.type = converted %Point.ref.loc28, %Z.facet [concrete = constants.%Z.facet]
  402. // CHECK:STDOUT: %impl.elem0: %.d52 = impl_witness_access constants.%Z.impl_witness, element0 [concrete = constants.%Zero.dec]
  403. // CHECK:STDOUT: %Zero.call: init %empty_tuple.type = call %impl.elem0()
  404. // CHECK:STDOUT: %.loc29_5.1: %empty_struct_type = struct_literal ()
  405. // CHECK:STDOUT: %Point.ref.loc29: type = name_ref Point, file.%Point.decl [concrete = constants.%Point]
  406. // CHECK:STDOUT: %.loc29_5.2: ref %Point = temporary_storage
  407. // CHECK:STDOUT: %.loc29_5.3: init %Point = class_init (), %.loc29_5.2 [concrete = constants.%Point.val]
  408. // CHECK:STDOUT: %.loc29_5.4: ref %Point = temporary %.loc29_5.2, %.loc29_5.3
  409. // CHECK:STDOUT: %.loc29_7.1: ref %Point = converted %.loc29_5.1, %.loc29_5.4
  410. // CHECK:STDOUT: %Z.ref.loc29: type = name_ref Z, file.%Z.decl [concrete = constants.%Z.type]
  411. // CHECK:STDOUT: %Method.ref: %Z.assoc_type = name_ref Method, @Z.%assoc1 [concrete = constants.%assoc1]
  412. // CHECK:STDOUT: %impl.elem1: %.462 = impl_witness_access constants.%Z.impl_witness, element1 [concrete = constants.%Method.2c2]
  413. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc29_7.1, %impl.elem1
  414. // CHECK:STDOUT: %.loc29_7.2: %Point = bind_value %.loc29_7.1
  415. // CHECK:STDOUT: %Method.call: init %empty_tuple.type = call %bound_method(%.loc29_7.2)
  416. // CHECK:STDOUT: return
  417. // CHECK:STDOUT: }
  418. // CHECK:STDOUT:
  419. // CHECK:STDOUT: specific @Zero.1(constants.%Self) {}
  420. // CHECK:STDOUT:
  421. // CHECK:STDOUT: specific @Method.1(constants.%Self) {
  422. // CHECK:STDOUT: %Self => constants.%Self
  423. // CHECK:STDOUT: %Self.as_type.loc5_19.1 => constants.%Self.as_type
  424. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.a40
  425. // CHECK:STDOUT: }
  426. // CHECK:STDOUT:
  427. // CHECK:STDOUT: specific @impl.6b5(constants.%Self) {
  428. // CHECK:STDOUT: !definition:
  429. // CHECK:STDOUT: %Self => constants.%Self
  430. // CHECK:STDOUT: %Zero.type => constants.%Zero.type.db4
  431. // CHECK:STDOUT: %Zero => constants.%Zero.8fb
  432. // CHECK:STDOUT: %Method.type => constants.%Method.type.163
  433. // CHECK:STDOUT: %Method => constants.%Method.84d
  434. // CHECK:STDOUT: }
  435. // CHECK:STDOUT:
  436. // CHECK:STDOUT: specific @Zero.2(constants.%Self) {}
  437. // CHECK:STDOUT:
  438. // CHECK:STDOUT: specific @Method.2(constants.%Self) {
  439. // CHECK:STDOUT: %Self => constants.%Self
  440. // CHECK:STDOUT: %Self.as_type.loc13_21.1 => constants.%Self.as_type
  441. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.a40
  442. // CHECK:STDOUT: }
  443. // CHECK:STDOUT:
  444. // CHECK:STDOUT: specific @impl.6b5(%Self) {}
  445. // CHECK:STDOUT:
  446. // CHECK:STDOUT: specific @Zero.1(constants.%Z.facet) {}
  447. // CHECK:STDOUT:
  448. // CHECK:STDOUT: specific @Method.1(constants.%Z.facet) {
  449. // CHECK:STDOUT: %Self => constants.%Z.facet
  450. // CHECK:STDOUT: %Self.as_type.loc5_19.1 => constants.%Point
  451. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.35b
  452. // CHECK:STDOUT: }
  453. // CHECK:STDOUT:
  454. // CHECK:STDOUT: --- fail_impl_as_other_interface.carbon
  455. // CHECK:STDOUT:
  456. // CHECK:STDOUT: constants {
  457. // CHECK:STDOUT: %A.type: type = facet_type <@A> [concrete]
  458. // CHECK:STDOUT: %Self.31d: %A.type = bind_symbolic_name Self, 0 [symbolic]
  459. // CHECK:STDOUT: %B.type.1c3: type = fn_type @B.1 [concrete]
  460. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  461. // CHECK:STDOUT: %B.b08: %B.type.1c3 = struct_value () [concrete]
  462. // CHECK:STDOUT: %A.assoc_type: type = assoc_entity_type @A [concrete]
  463. // CHECK:STDOUT: %assoc0: %A.assoc_type = assoc_entity element0, @A.%B.decl [concrete]
  464. // CHECK:STDOUT: %C.type: type = facet_type <@C> [concrete]
  465. // CHECK:STDOUT: %Self.02e: %C.type = bind_symbolic_name Self, 0 [symbolic]
  466. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  467. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  468. // CHECK:STDOUT: %X: type = class_type @X [concrete]
  469. // CHECK:STDOUT: %A.impl_witness: <witness> = impl_witness @X.%A.impl_witness_table [concrete]
  470. // CHECK:STDOUT: %B.type.d47: type = fn_type @B.2 [concrete]
  471. // CHECK:STDOUT: %B.4af: %B.type.d47 = struct_value () [concrete]
  472. // CHECK:STDOUT: %A.facet: %A.type = facet_value %X, (%A.impl_witness) [concrete]
  473. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  474. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  475. // CHECK:STDOUT: }
  476. // CHECK:STDOUT:
  477. // CHECK:STDOUT: imports {
  478. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  479. // CHECK:STDOUT: import Core//prelude
  480. // CHECK:STDOUT: }
  481. // CHECK:STDOUT: }
  482. // CHECK:STDOUT:
  483. // CHECK:STDOUT: file {
  484. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  485. // CHECK:STDOUT: .Core = imports.%Core
  486. // CHECK:STDOUT: .A = %A.decl
  487. // CHECK:STDOUT: .C = %C.decl
  488. // CHECK:STDOUT: .G = %G.decl
  489. // CHECK:STDOUT: .X = %X.decl
  490. // CHECK:STDOUT: }
  491. // CHECK:STDOUT: %Core.import = import Core
  492. // CHECK:STDOUT: %A.decl: type = interface_decl @A [concrete = constants.%A.type] {} {}
  493. // CHECK:STDOUT: %C.decl: type = interface_decl @C [concrete = constants.%C.type] {} {}
  494. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  495. // CHECK:STDOUT: %X.decl: type = class_decl @X [concrete = constants.%X] {} {}
  496. // CHECK:STDOUT: }
  497. // CHECK:STDOUT:
  498. // CHECK:STDOUT: interface @A {
  499. // CHECK:STDOUT: %Self: %A.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self.31d]
  500. // CHECK:STDOUT: %B.decl: %B.type.1c3 = fn_decl @B.1 [concrete = constants.%B.b08] {} {}
  501. // CHECK:STDOUT: %assoc0: %A.assoc_type = assoc_entity element0, %B.decl [concrete = constants.%assoc0]
  502. // CHECK:STDOUT:
  503. // CHECK:STDOUT: !members:
  504. // CHECK:STDOUT: .Self = %Self
  505. // CHECK:STDOUT: .B = %assoc0
  506. // CHECK:STDOUT: witness = (%B.decl)
  507. // CHECK:STDOUT: }
  508. // CHECK:STDOUT:
  509. // CHECK:STDOUT: interface @C {
  510. // CHECK:STDOUT: %Self: %C.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self.02e]
  511. // CHECK:STDOUT:
  512. // CHECK:STDOUT: !members:
  513. // CHECK:STDOUT: .Self = %Self
  514. // CHECK:STDOUT: witness = ()
  515. // CHECK:STDOUT: }
  516. // CHECK:STDOUT:
  517. // CHECK:STDOUT: impl @impl.3b4: %Self.ref as %A.ref {
  518. // CHECK:STDOUT: impl_decl @impl.4cc [concrete] {} {
  519. // CHECK:STDOUT: %Self.ref: type = name_ref Self, <error> [concrete = <error>]
  520. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C.type]
  521. // CHECK:STDOUT: }
  522. // CHECK:STDOUT: %B.decl: %B.type.d47 = fn_decl @B.2 [concrete = constants.%B.4af] {} {}
  523. // CHECK:STDOUT:
  524. // CHECK:STDOUT: !members:
  525. // CHECK:STDOUT: .C = <poisoned>
  526. // CHECK:STDOUT: .B = %B.decl
  527. // CHECK:STDOUT: .G = <poisoned>
  528. // CHECK:STDOUT: witness = @X.%A.impl_witness
  529. // CHECK:STDOUT: }
  530. // CHECK:STDOUT:
  531. // CHECK:STDOUT: impl @impl.4cc: %Self.ref as %C.ref {
  532. // CHECK:STDOUT: !members:
  533. // CHECK:STDOUT: witness = <error>
  534. // CHECK:STDOUT: }
  535. // CHECK:STDOUT:
  536. // CHECK:STDOUT: class @X {
  537. // CHECK:STDOUT: impl_decl @impl.3b4 [concrete] {} {
  538. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%X [concrete = constants.%X]
  539. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A.type]
  540. // CHECK:STDOUT: }
  541. // CHECK:STDOUT: %A.impl_witness_table = impl_witness_table (@impl.3b4.%B.decl), @impl.3b4 [concrete]
  542. // CHECK:STDOUT: %A.impl_witness: <witness> = impl_witness %A.impl_witness_table [concrete = constants.%A.impl_witness]
  543. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  544. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  545. // CHECK:STDOUT: complete_type_witness = %complete_type
  546. // CHECK:STDOUT:
  547. // CHECK:STDOUT: !members:
  548. // CHECK:STDOUT: .Self = constants.%X
  549. // CHECK:STDOUT: .A = <poisoned>
  550. // CHECK:STDOUT: .C = <poisoned>
  551. // CHECK:STDOUT: .G = <poisoned>
  552. // CHECK:STDOUT: }
  553. // CHECK:STDOUT:
  554. // CHECK:STDOUT: generic fn @B.1(@A.%Self: %A.type) {
  555. // CHECK:STDOUT: fn();
  556. // CHECK:STDOUT: }
  557. // CHECK:STDOUT:
  558. // CHECK:STDOUT: fn @G() {
  559. // CHECK:STDOUT: !entry:
  560. // CHECK:STDOUT: return
  561. // CHECK:STDOUT: }
  562. // CHECK:STDOUT:
  563. // CHECK:STDOUT: fn @B.2() {
  564. // CHECK:STDOUT: !entry:
  565. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
  566. // CHECK:STDOUT: %G.call: init %empty_tuple.type = call %G.ref()
  567. // CHECK:STDOUT: return
  568. // CHECK:STDOUT: }
  569. // CHECK:STDOUT:
  570. // CHECK:STDOUT: specific @B.1(constants.%Self.31d) {}
  571. // CHECK:STDOUT:
  572. // CHECK:STDOUT: specific @B.1(constants.%A.facet) {}
  573. // CHECK:STDOUT:
  574. // CHECK:STDOUT: --- include_files/destroy.carbon
  575. // CHECK:STDOUT:
  576. // CHECK:STDOUT: file {
  577. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {}
  578. // CHECK:STDOUT: }
  579. // CHECK:STDOUT: