fail_impl_as_scope.carbon 30 KB

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