eq.carbon 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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. // --- prelude.carbon
  7. package Core api;
  8. import library "prelude";
  9. interface Eq {
  10. fn Equal[self: Self](other: Self) -> bool;
  11. fn NotEqual[self: Self](other: Self) -> bool;
  12. }
  13. // --- user.carbon
  14. package User api;
  15. import Core;
  16. class C {};
  17. impl C as Core.Eq {
  18. fn Equal[self: C](other: C) -> bool;
  19. fn NotEqual[self: C](other: C) -> bool;
  20. }
  21. fn TestEqual(a: C, b: C) -> bool {
  22. return a == b;
  23. }
  24. fn TestNotEqual(a: C, b: C) -> bool {
  25. return a != b;
  26. }
  27. // --- fail_no_impl.carbon
  28. package FailNoImpl api;
  29. import Core;
  30. class D {};
  31. fn TestEqual(a: D, b: D) -> bool {
  32. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: ERROR: Cannot access member of interface Eq in type D that does not implement that interface.
  33. // CHECK:STDERR: return a == b;
  34. // CHECK:STDERR: ^~~~~~
  35. // CHECK:STDERR:
  36. return a == b;
  37. }
  38. fn TestNotEqual(a: D, b: D) -> bool {
  39. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: ERROR: Cannot access member of interface Eq in type D that does not implement that interface.
  40. // CHECK:STDERR: return a != b;
  41. // CHECK:STDERR: ^~~~~~
  42. // CHECK:STDERR:
  43. return a != b;
  44. }
  45. // --- fail_no_impl_for_args.carbon
  46. package FailNoImplForArgs api;
  47. import Core;
  48. class C {};
  49. class D {};
  50. impl C as Core.Eq {
  51. fn Equal[self: C](other: C) -> bool;
  52. fn NotEqual[self: C](other: C) -> bool;
  53. }
  54. fn TestRhsBad(a: C, b: D) -> bool {
  55. // CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE+7]]:10: ERROR: Cannot implicitly convert from `D` to `C`.
  56. // CHECK:STDERR: return a == b;
  57. // CHECK:STDERR: ^~~~~~
  58. // CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE-8]]:3: Initializing parameter 1 of function declared here.
  59. // CHECK:STDERR: fn Equal[self: C](other: C) -> bool;
  60. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. // CHECK:STDERR:
  62. return a == b;
  63. }
  64. fn TestLhsBad(a: D, b: C) -> bool {
  65. // CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE+3]]:10: ERROR: Cannot access member of interface Eq in type D that does not implement that interface.
  66. // CHECK:STDERR: return a != b;
  67. // CHECK:STDERR: ^~~~~~
  68. return a != b;
  69. }
  70. // CHECK:STDOUT: --- prelude.carbon
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: constants {
  73. // CHECK:STDOUT: %.1: type = interface_type @Eq [template]
  74. // CHECK:STDOUT: %Self: Eq = bind_symbolic_name Self 0 [symbolic]
  75. // CHECK:STDOUT: %Equal: type = fn_type @Equal [template]
  76. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  77. // CHECK:STDOUT: %struct.1: Equal = struct_value () [template]
  78. // CHECK:STDOUT: %.3: type = assoc_entity_type @Eq, Equal [template]
  79. // CHECK:STDOUT: %.4: <associated Equal in Eq> = assoc_entity element0, @Eq.%Equal.decl [template]
  80. // CHECK:STDOUT: %NotEqual: type = fn_type @NotEqual [template]
  81. // CHECK:STDOUT: %struct.2: NotEqual = struct_value () [template]
  82. // CHECK:STDOUT: %.5: type = assoc_entity_type @Eq, NotEqual [template]
  83. // CHECK:STDOUT: %.6: <associated NotEqual in Eq> = assoc_entity element1, @Eq.%NotEqual.decl [template]
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: file {
  87. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  88. // CHECK:STDOUT: .Eq = %Eq.decl
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %Eq.decl: type = interface_decl @Eq [template = constants.%.1] {}
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: interface @Eq {
  94. // CHECK:STDOUT: %Self: Eq = bind_symbolic_name Self 0 [symbolic = constants.%Self]
  95. // CHECK:STDOUT: %Equal.decl: Equal = fn_decl @Equal [template = constants.%struct.1] {
  96. // CHECK:STDOUT: %Self.ref.loc7_18: Eq = name_ref Self, %Self [symbolic = constants.%Self]
  97. // CHECK:STDOUT: %.loc7_18.1: type = facet_type_access %Self.ref.loc7_18 [symbolic = constants.%Self]
  98. // CHECK:STDOUT: %.loc7_18.2: type = converted %Self.ref.loc7_18, %.loc7_18.1 [symbolic = constants.%Self]
  99. // CHECK:STDOUT: %self.loc7_12.1: Self = param self
  100. // CHECK:STDOUT: %self.loc7_12.2: Self = bind_name self, %self.loc7_12.1
  101. // CHECK:STDOUT: %Self.ref.loc7_31: Eq = name_ref Self, %Self [symbolic = constants.%Self]
  102. // CHECK:STDOUT: %.loc7_31.1: type = facet_type_access %Self.ref.loc7_31 [symbolic = constants.%Self]
  103. // CHECK:STDOUT: %.loc7_31.2: type = converted %Self.ref.loc7_31, %.loc7_31.1 [symbolic = constants.%Self]
  104. // CHECK:STDOUT: %other.loc7_24.1: Self = param other
  105. // CHECK:STDOUT: %other.loc7_24.2: Self = bind_name other, %other.loc7_24.1
  106. // CHECK:STDOUT: %return.var.loc7: ref bool = var <return slot>
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %.loc7_44: <associated Equal in Eq> = assoc_entity element0, %Equal.decl [template = constants.%.4]
  109. // CHECK:STDOUT: %NotEqual.decl: NotEqual = fn_decl @NotEqual [template = constants.%struct.2] {
  110. // CHECK:STDOUT: %Self.ref.loc8_21: Eq = name_ref Self, %Self [symbolic = constants.%Self]
  111. // CHECK:STDOUT: %.loc8_21.1: type = facet_type_access %Self.ref.loc8_21 [symbolic = constants.%Self]
  112. // CHECK:STDOUT: %.loc8_21.2: type = converted %Self.ref.loc8_21, %.loc8_21.1 [symbolic = constants.%Self]
  113. // CHECK:STDOUT: %self.loc8_15.1: Self = param self
  114. // CHECK:STDOUT: %self.loc8_15.2: Self = bind_name self, %self.loc8_15.1
  115. // CHECK:STDOUT: %Self.ref.loc8_34: Eq = name_ref Self, %Self [symbolic = constants.%Self]
  116. // CHECK:STDOUT: %.loc8_34.1: type = facet_type_access %Self.ref.loc8_34 [symbolic = constants.%Self]
  117. // CHECK:STDOUT: %.loc8_34.2: type = converted %Self.ref.loc8_34, %.loc8_34.1 [symbolic = constants.%Self]
  118. // CHECK:STDOUT: %other.loc8_27.1: Self = param other
  119. // CHECK:STDOUT: %other.loc8_27.2: Self = bind_name other, %other.loc8_27.1
  120. // CHECK:STDOUT: %return.var.loc8: ref bool = var <return slot>
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %.loc8_47: <associated NotEqual in Eq> = assoc_entity element1, %NotEqual.decl [template = constants.%.6]
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: !members:
  125. // CHECK:STDOUT: .Self = %Self
  126. // CHECK:STDOUT: .Equal = %.loc7_44
  127. // CHECK:STDOUT: .NotEqual = %.loc8_47
  128. // CHECK:STDOUT: witness = (%Equal.decl, %NotEqual.decl)
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn @Equal[@Eq.%self.loc7_12.2: Self](@Eq.%other.loc7_24.2: Self) -> bool;
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: fn @NotEqual[@Eq.%self.loc8_15.2: Self](@Eq.%other.loc8_27.2: Self) -> bool;
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: --- user.carbon
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: constants {
  138. // CHECK:STDOUT: %C: type = class_type @C [template]
  139. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  140. // CHECK:STDOUT: %.2: type = interface_type @Eq [template]
  141. // CHECK:STDOUT: %Self: Eq = bind_symbolic_name Self 0 [symbolic]
  142. // CHECK:STDOUT: %Equal.1: type = fn_type @Equal.1 [template]
  143. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  144. // CHECK:STDOUT: %struct.1: Equal = struct_value () [template]
  145. // CHECK:STDOUT: %NotEqual.1: type = fn_type @NotEqual.1 [template]
  146. // CHECK:STDOUT: %struct.2: NotEqual = struct_value () [template]
  147. // CHECK:STDOUT: %Equal.2: type = fn_type @Equal.2 [template]
  148. // CHECK:STDOUT: %struct.3: Equal = struct_value () [template]
  149. // CHECK:STDOUT: %NotEqual.2: type = fn_type @NotEqual.2 [template]
  150. // CHECK:STDOUT: %struct.4: NotEqual = struct_value () [template]
  151. // CHECK:STDOUT: %.4: <witness> = interface_witness (%struct.1, %struct.2) [template]
  152. // CHECK:STDOUT: %TestEqual: type = fn_type @TestEqual [template]
  153. // CHECK:STDOUT: %struct.5: TestEqual = struct_value () [template]
  154. // CHECK:STDOUT: %.5: type = ptr_type {} [template]
  155. // CHECK:STDOUT: %.6: type = assoc_entity_type @Eq, Equal [template]
  156. // CHECK:STDOUT: %.7: <associated Equal in Eq> = assoc_entity element0, file.%import_ref.8 [template]
  157. // CHECK:STDOUT: %TestNotEqual: type = fn_type @TestNotEqual [template]
  158. // CHECK:STDOUT: %struct.6: TestNotEqual = struct_value () [template]
  159. // CHECK:STDOUT: %.8: type = assoc_entity_type @Eq, NotEqual [template]
  160. // CHECK:STDOUT: %.9: <associated NotEqual in Eq> = assoc_entity element1, file.%import_ref.10 [template]
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: file {
  164. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  165. // CHECK:STDOUT: .Core = %Core
  166. // CHECK:STDOUT: .C = %C.decl
  167. // CHECK:STDOUT: .TestEqual = %TestEqual.decl
  168. // CHECK:STDOUT: .TestNotEqual = %TestNotEqual.decl
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  171. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  172. // CHECK:STDOUT: %import_ref.1: type = import_ref ir2, inst+1, loaded [template = constants.%.2]
  173. // CHECK:STDOUT: %import_ref.2 = import_ref ir2, inst+3, unloaded
  174. // CHECK:STDOUT: %import_ref.3: <associated Equal in Eq> = import_ref ir2, inst+21, loaded [template = constants.%.7]
  175. // CHECK:STDOUT: %import_ref.4: <associated NotEqual in Eq> = import_ref ir2, inst+38, loaded [template = constants.%.9]
  176. // CHECK:STDOUT: %import_ref.5: Equal = import_ref ir2, inst+16, loaded [template = constants.%struct.3]
  177. // CHECK:STDOUT: %import_ref.6: NotEqual = import_ref ir2, inst+34, loaded [template = constants.%struct.4]
  178. // CHECK:STDOUT: impl_decl @impl {
  179. // CHECK:STDOUT: %C.ref.loc8: type = name_ref C, %C.decl [template = constants.%C]
  180. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, %Core [template = %Core]
  181. // CHECK:STDOUT: %Eq.ref: type = name_ref Eq, %import_ref.1 [template = constants.%.2]
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT: %TestEqual.decl: TestEqual = fn_decl @TestEqual [template = constants.%struct.5] {
  184. // CHECK:STDOUT: %C.ref.loc13_17: type = name_ref C, %C.decl [template = constants.%C]
  185. // CHECK:STDOUT: %a.loc13_14.1: C = param a
  186. // CHECK:STDOUT: @TestEqual.%a: C = bind_name a, %a.loc13_14.1
  187. // CHECK:STDOUT: %C.ref.loc13_23: type = name_ref C, %C.decl [template = constants.%C]
  188. // CHECK:STDOUT: %b.loc13_20.1: C = param b
  189. // CHECK:STDOUT: @TestEqual.%b: C = bind_name b, %b.loc13_20.1
  190. // CHECK:STDOUT: @TestEqual.%return: ref bool = var <return slot>
  191. // CHECK:STDOUT: }
  192. // CHECK:STDOUT: %import_ref.7: type = import_ref ir2, inst+1, loaded [template = constants.%.2]
  193. // CHECK:STDOUT: %import_ref.8 = import_ref ir2, inst+16, unloaded
  194. // CHECK:STDOUT: %TestNotEqual.decl: TestNotEqual = fn_decl @TestNotEqual [template = constants.%struct.6] {
  195. // CHECK:STDOUT: %C.ref.loc17_20: type = name_ref C, %C.decl [template = constants.%C]
  196. // CHECK:STDOUT: %a.loc17_17.1: C = param a
  197. // CHECK:STDOUT: @TestNotEqual.%a: C = bind_name a, %a.loc17_17.1
  198. // CHECK:STDOUT: %C.ref.loc17_26: type = name_ref C, %C.decl [template = constants.%C]
  199. // CHECK:STDOUT: %b.loc17_23.1: C = param b
  200. // CHECK:STDOUT: @TestNotEqual.%b: C = bind_name b, %b.loc17_23.1
  201. // CHECK:STDOUT: @TestNotEqual.%return: ref bool = var <return slot>
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT: %import_ref.9: type = import_ref ir2, inst+1, loaded [template = constants.%.2]
  204. // CHECK:STDOUT: %import_ref.10 = import_ref ir2, inst+34, unloaded
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: interface @Eq {
  208. // CHECK:STDOUT: !members:
  209. // CHECK:STDOUT: .Self = file.%import_ref.2
  210. // CHECK:STDOUT: .Equal = file.%import_ref.3
  211. // CHECK:STDOUT: .NotEqual = file.%import_ref.4
  212. // CHECK:STDOUT: witness = (file.%import_ref.5, file.%import_ref.6)
  213. // CHECK:STDOUT: }
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: impl @impl: C as Eq {
  216. // CHECK:STDOUT: %Equal.decl: Equal = fn_decl @Equal.1 [template = constants.%struct.1] {
  217. // CHECK:STDOUT: %C.ref.loc9_18: type = name_ref C, file.%C.decl [template = constants.%C]
  218. // CHECK:STDOUT: %self.loc9_12.1: C = param self
  219. // CHECK:STDOUT: %self.loc9_12.2: C = bind_name self, %self.loc9_12.1
  220. // CHECK:STDOUT: %C.ref.loc9_28: type = name_ref C, file.%C.decl [template = constants.%C]
  221. // CHECK:STDOUT: %other.loc9_21.1: C = param other
  222. // CHECK:STDOUT: %other.loc9_21.2: C = bind_name other, %other.loc9_21.1
  223. // CHECK:STDOUT: %return.var.loc9: ref bool = var <return slot>
  224. // CHECK:STDOUT: }
  225. // CHECK:STDOUT: %NotEqual.decl: NotEqual = fn_decl @NotEqual.1 [template = constants.%struct.2] {
  226. // CHECK:STDOUT: %C.ref.loc10_21: type = name_ref C, file.%C.decl [template = constants.%C]
  227. // CHECK:STDOUT: %self.loc10_15.1: C = param self
  228. // CHECK:STDOUT: %self.loc10_15.2: C = bind_name self, %self.loc10_15.1
  229. // CHECK:STDOUT: %C.ref.loc10_31: type = name_ref C, file.%C.decl [template = constants.%C]
  230. // CHECK:STDOUT: %other.loc10_24.1: C = param other
  231. // CHECK:STDOUT: %other.loc10_24.2: C = bind_name other, %other.loc10_24.1
  232. // CHECK:STDOUT: %return.var.loc10: ref bool = var <return slot>
  233. // CHECK:STDOUT: }
  234. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Equal.decl, %NotEqual.decl) [template = constants.%.4]
  235. // CHECK:STDOUT:
  236. // CHECK:STDOUT: !members:
  237. // CHECK:STDOUT: .Equal = %Equal.decl
  238. // CHECK:STDOUT: .NotEqual = %NotEqual.decl
  239. // CHECK:STDOUT: witness = %.1
  240. // CHECK:STDOUT: }
  241. // CHECK:STDOUT:
  242. // CHECK:STDOUT: class @C {
  243. // CHECK:STDOUT: !members:
  244. // CHECK:STDOUT: .Self = constants.%C
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: fn @Equal.1[@impl.%self.loc9_12.2: C](@impl.%other.loc9_21.2: C) -> bool;
  248. // CHECK:STDOUT:
  249. // CHECK:STDOUT: fn @NotEqual.1[@impl.%self.loc10_15.2: C](@impl.%other.loc10_24.2: C) -> bool;
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: fn @Equal.2[%self: Self](%other: Self) -> bool;
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: fn @NotEqual.2[%self: Self](%other: Self) -> bool;
  254. // CHECK:STDOUT:
  255. // CHECK:STDOUT: fn @TestEqual(%a: C, %b: C) -> bool {
  256. // CHECK:STDOUT: !entry:
  257. // CHECK:STDOUT: %a.ref: C = name_ref a, %a
  258. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  259. // CHECK:STDOUT: %.1: Equal = interface_witness_access @impl.%.1, element0 [template = constants.%struct.1]
  260. // CHECK:STDOUT: %.loc14_12: <bound method> = bound_method %a.ref, %.1
  261. // CHECK:STDOUT: %Equal.call: init bool = call %.loc14_12(%a.ref, %b.ref)
  262. // CHECK:STDOUT: %.loc14_16.1: bool = value_of_initializer %Equal.call
  263. // CHECK:STDOUT: %.loc14_16.2: bool = converted %Equal.call, %.loc14_16.1
  264. // CHECK:STDOUT: return %.loc14_16.2
  265. // CHECK:STDOUT: }
  266. // CHECK:STDOUT:
  267. // CHECK:STDOUT: fn @TestNotEqual(%a: C, %b: C) -> bool {
  268. // CHECK:STDOUT: !entry:
  269. // CHECK:STDOUT: %a.ref: C = name_ref a, %a
  270. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  271. // CHECK:STDOUT: %.1: NotEqual = interface_witness_access @impl.%.1, element1 [template = constants.%struct.2]
  272. // CHECK:STDOUT: %.loc18_12: <bound method> = bound_method %a.ref, %.1
  273. // CHECK:STDOUT: %NotEqual.call: init bool = call %.loc18_12(%a.ref, %b.ref)
  274. // CHECK:STDOUT: %.loc18_16.1: bool = value_of_initializer %NotEqual.call
  275. // CHECK:STDOUT: %.loc18_16.2: bool = converted %NotEqual.call, %.loc18_16.1
  276. // CHECK:STDOUT: return %.loc18_16.2
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT:
  279. // CHECK:STDOUT: --- fail_no_impl.carbon
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: constants {
  282. // CHECK:STDOUT: %D: type = class_type @D [template]
  283. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  284. // CHECK:STDOUT: %TestEqual: type = fn_type @TestEqual [template]
  285. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  286. // CHECK:STDOUT: %struct.1: TestEqual = struct_value () [template]
  287. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  288. // CHECK:STDOUT: %.4: type = interface_type @Eq [template]
  289. // CHECK:STDOUT: %Self: Eq = bind_symbolic_name Self 0 [symbolic]
  290. // CHECK:STDOUT: %Equal: type = fn_type @Equal [template]
  291. // CHECK:STDOUT: %struct.2: Equal = struct_value () [template]
  292. // CHECK:STDOUT: %.5: type = assoc_entity_type @Eq, Equal [template]
  293. // CHECK:STDOUT: %.6: <associated Equal in Eq> = assoc_entity element0, file.%import_ref.7 [template]
  294. // CHECK:STDOUT: %TestNotEqual: type = fn_type @TestNotEqual [template]
  295. // CHECK:STDOUT: %struct.3: TestNotEqual = struct_value () [template]
  296. // CHECK:STDOUT: %NotEqual: type = fn_type @NotEqual [template]
  297. // CHECK:STDOUT: %struct.4: NotEqual = struct_value () [template]
  298. // CHECK:STDOUT: %.7: type = assoc_entity_type @Eq, NotEqual [template]
  299. // CHECK:STDOUT: %.8: <associated NotEqual in Eq> = assoc_entity element1, file.%import_ref.9 [template]
  300. // CHECK:STDOUT: }
  301. // CHECK:STDOUT:
  302. // CHECK:STDOUT: file {
  303. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  304. // CHECK:STDOUT: .Core = %Core
  305. // CHECK:STDOUT: .D = %D.decl
  306. // CHECK:STDOUT: .TestEqual = %TestEqual.decl
  307. // CHECK:STDOUT: .TestNotEqual = %TestNotEqual.decl
  308. // CHECK:STDOUT: }
  309. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  310. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {}
  311. // CHECK:STDOUT: %TestEqual.decl: TestEqual = fn_decl @TestEqual [template = constants.%struct.1] {
  312. // CHECK:STDOUT: %D.ref.loc8_17: type = name_ref D, %D.decl [template = constants.%D]
  313. // CHECK:STDOUT: %a.loc8_14.1: D = param a
  314. // CHECK:STDOUT: @TestEqual.%a: D = bind_name a, %a.loc8_14.1
  315. // CHECK:STDOUT: %D.ref.loc8_23: type = name_ref D, %D.decl [template = constants.%D]
  316. // CHECK:STDOUT: %b.loc8_20.1: D = param b
  317. // CHECK:STDOUT: @TestEqual.%b: D = bind_name b, %b.loc8_20.1
  318. // CHECK:STDOUT: @TestEqual.%return: ref bool = var <return slot>
  319. // CHECK:STDOUT: }
  320. // CHECK:STDOUT: %import_ref.1: type = import_ref ir2, inst+1, loaded [template = constants.%.4]
  321. // CHECK:STDOUT: %import_ref.2 = import_ref ir2, inst+3, unloaded
  322. // CHECK:STDOUT: %import_ref.3: <associated Equal in Eq> = import_ref ir2, inst+21, loaded [template = constants.%.6]
  323. // CHECK:STDOUT: %import_ref.4: <associated NotEqual in Eq> = import_ref ir2, inst+38, loaded [template = constants.%.8]
  324. // CHECK:STDOUT: %import_ref.5 = import_ref ir2, inst+16, unloaded
  325. // CHECK:STDOUT: %import_ref.6 = import_ref ir2, inst+34, unloaded
  326. // CHECK:STDOUT: %import_ref.7 = import_ref ir2, inst+16, unloaded
  327. // CHECK:STDOUT: %TestNotEqual.decl: TestNotEqual = fn_decl @TestNotEqual [template = constants.%struct.3] {
  328. // CHECK:STDOUT: %D.ref.loc16_20: type = name_ref D, %D.decl [template = constants.%D]
  329. // CHECK:STDOUT: %a.loc16_17.1: D = param a
  330. // CHECK:STDOUT: @TestNotEqual.%a: D = bind_name a, %a.loc16_17.1
  331. // CHECK:STDOUT: %D.ref.loc16_26: type = name_ref D, %D.decl [template = constants.%D]
  332. // CHECK:STDOUT: %b.loc16_23.1: D = param b
  333. // CHECK:STDOUT: @TestNotEqual.%b: D = bind_name b, %b.loc16_23.1
  334. // CHECK:STDOUT: @TestNotEqual.%return: ref bool = var <return slot>
  335. // CHECK:STDOUT: }
  336. // CHECK:STDOUT: %import_ref.8: type = import_ref ir2, inst+1, loaded [template = constants.%.4]
  337. // CHECK:STDOUT: %import_ref.9 = import_ref ir2, inst+34, unloaded
  338. // CHECK:STDOUT: }
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: interface @Eq {
  341. // CHECK:STDOUT: !members:
  342. // CHECK:STDOUT: .Self = file.%import_ref.2
  343. // CHECK:STDOUT: .Equal = file.%import_ref.3
  344. // CHECK:STDOUT: .NotEqual = file.%import_ref.4
  345. // CHECK:STDOUT: witness = (file.%import_ref.5, file.%import_ref.6)
  346. // CHECK:STDOUT: }
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: class @D {
  349. // CHECK:STDOUT: !members:
  350. // CHECK:STDOUT: .Self = constants.%D
  351. // CHECK:STDOUT: }
  352. // CHECK:STDOUT:
  353. // CHECK:STDOUT: fn @TestEqual(%a: D, %b: D) -> bool {
  354. // CHECK:STDOUT: !entry:
  355. // CHECK:STDOUT: %a.ref: D = name_ref a, %a
  356. // CHECK:STDOUT: %b.ref: D = name_ref b, %b
  357. // CHECK:STDOUT: return <error>
  358. // CHECK:STDOUT: }
  359. // CHECK:STDOUT:
  360. // CHECK:STDOUT: fn @Equal[%self: Self](%other: Self) -> bool;
  361. // CHECK:STDOUT:
  362. // CHECK:STDOUT: fn @TestNotEqual(%a: D, %b: D) -> bool {
  363. // CHECK:STDOUT: !entry:
  364. // CHECK:STDOUT: %a.ref: D = name_ref a, %a
  365. // CHECK:STDOUT: %b.ref: D = name_ref b, %b
  366. // CHECK:STDOUT: return <error>
  367. // CHECK:STDOUT: }
  368. // CHECK:STDOUT:
  369. // CHECK:STDOUT: fn @NotEqual[%self: Self](%other: Self) -> bool;
  370. // CHECK:STDOUT:
  371. // CHECK:STDOUT: --- fail_no_impl_for_args.carbon
  372. // CHECK:STDOUT:
  373. // CHECK:STDOUT: constants {
  374. // CHECK:STDOUT: %C: type = class_type @C [template]
  375. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  376. // CHECK:STDOUT: %D: type = class_type @D [template]
  377. // CHECK:STDOUT: %.2: type = interface_type @Eq [template]
  378. // CHECK:STDOUT: %Self: Eq = bind_symbolic_name Self 0 [symbolic]
  379. // CHECK:STDOUT: %Equal.1: type = fn_type @Equal.1 [template]
  380. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  381. // CHECK:STDOUT: %struct.1: Equal = struct_value () [template]
  382. // CHECK:STDOUT: %NotEqual.1: type = fn_type @NotEqual.1 [template]
  383. // CHECK:STDOUT: %struct.2: NotEqual = struct_value () [template]
  384. // CHECK:STDOUT: %Equal.2: type = fn_type @Equal.2 [template]
  385. // CHECK:STDOUT: %struct.3: Equal = struct_value () [template]
  386. // CHECK:STDOUT: %NotEqual.2: type = fn_type @NotEqual.2 [template]
  387. // CHECK:STDOUT: %struct.4: NotEqual = struct_value () [template]
  388. // CHECK:STDOUT: %.4: <witness> = interface_witness (%struct.1, %struct.2) [template]
  389. // CHECK:STDOUT: %TestRhsBad: type = fn_type @TestRhsBad [template]
  390. // CHECK:STDOUT: %struct.5: TestRhsBad = struct_value () [template]
  391. // CHECK:STDOUT: %.5: type = ptr_type {} [template]
  392. // CHECK:STDOUT: %.6: type = assoc_entity_type @Eq, Equal [template]
  393. // CHECK:STDOUT: %.7: <associated Equal in Eq> = assoc_entity element0, file.%import_ref.8 [template]
  394. // CHECK:STDOUT: %TestLhsBad: type = fn_type @TestLhsBad [template]
  395. // CHECK:STDOUT: %struct.6: TestLhsBad = struct_value () [template]
  396. // CHECK:STDOUT: %.8: type = assoc_entity_type @Eq, NotEqual [template]
  397. // CHECK:STDOUT: %.9: <associated NotEqual in Eq> = assoc_entity element1, file.%import_ref.10 [template]
  398. // CHECK:STDOUT: }
  399. // CHECK:STDOUT:
  400. // CHECK:STDOUT: file {
  401. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  402. // CHECK:STDOUT: .Core = %Core
  403. // CHECK:STDOUT: .C = %C.decl
  404. // CHECK:STDOUT: .D = %D.decl
  405. // CHECK:STDOUT: .TestRhsBad = %TestRhsBad.decl
  406. // CHECK:STDOUT: .TestLhsBad = %TestLhsBad.decl
  407. // CHECK:STDOUT: }
  408. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  409. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  410. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {}
  411. // CHECK:STDOUT: %import_ref.1: type = import_ref ir2, inst+1, loaded [template = constants.%.2]
  412. // CHECK:STDOUT: %import_ref.2 = import_ref ir2, inst+3, unloaded
  413. // CHECK:STDOUT: %import_ref.3: <associated Equal in Eq> = import_ref ir2, inst+21, loaded [template = constants.%.7]
  414. // CHECK:STDOUT: %import_ref.4: <associated NotEqual in Eq> = import_ref ir2, inst+38, loaded [template = constants.%.9]
  415. // CHECK:STDOUT: %import_ref.5: Equal = import_ref ir2, inst+16, loaded [template = constants.%struct.3]
  416. // CHECK:STDOUT: %import_ref.6: NotEqual = import_ref ir2, inst+34, loaded [template = constants.%struct.4]
  417. // CHECK:STDOUT: impl_decl @impl {
  418. // CHECK:STDOUT: %C.ref.loc9: type = name_ref C, %C.decl [template = constants.%C]
  419. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, %Core [template = %Core]
  420. // CHECK:STDOUT: %Eq.ref: type = name_ref Eq, %import_ref.1 [template = constants.%.2]
  421. // CHECK:STDOUT: }
  422. // CHECK:STDOUT: %TestRhsBad.decl: TestRhsBad = fn_decl @TestRhsBad [template = constants.%struct.5] {
  423. // CHECK:STDOUT: %C.ref.loc14: type = name_ref C, %C.decl [template = constants.%C]
  424. // CHECK:STDOUT: %a.loc14_15.1: C = param a
  425. // CHECK:STDOUT: @TestRhsBad.%a: C = bind_name a, %a.loc14_15.1
  426. // CHECK:STDOUT: %D.ref.loc14: type = name_ref D, %D.decl [template = constants.%D]
  427. // CHECK:STDOUT: %b.loc14_21.1: D = param b
  428. // CHECK:STDOUT: @TestRhsBad.%b: D = bind_name b, %b.loc14_21.1
  429. // CHECK:STDOUT: @TestRhsBad.%return: ref bool = var <return slot>
  430. // CHECK:STDOUT: }
  431. // CHECK:STDOUT: %import_ref.7: type = import_ref ir2, inst+1, loaded [template = constants.%.2]
  432. // CHECK:STDOUT: %import_ref.8 = import_ref ir2, inst+16, unloaded
  433. // CHECK:STDOUT: %TestLhsBad.decl: TestLhsBad = fn_decl @TestLhsBad [template = constants.%struct.6] {
  434. // CHECK:STDOUT: %D.ref.loc25: type = name_ref D, %D.decl [template = constants.%D]
  435. // CHECK:STDOUT: %a.loc25_15.1: D = param a
  436. // CHECK:STDOUT: @TestLhsBad.%a: D = bind_name a, %a.loc25_15.1
  437. // CHECK:STDOUT: %C.ref.loc25: type = name_ref C, %C.decl [template = constants.%C]
  438. // CHECK:STDOUT: %b.loc25_21.1: C = param b
  439. // CHECK:STDOUT: @TestLhsBad.%b: C = bind_name b, %b.loc25_21.1
  440. // CHECK:STDOUT: @TestLhsBad.%return: ref bool = var <return slot>
  441. // CHECK:STDOUT: }
  442. // CHECK:STDOUT: %import_ref.9: type = import_ref ir2, inst+1, loaded [template = constants.%.2]
  443. // CHECK:STDOUT: %import_ref.10 = import_ref ir2, inst+34, unloaded
  444. // CHECK:STDOUT: }
  445. // CHECK:STDOUT:
  446. // CHECK:STDOUT: interface @Eq {
  447. // CHECK:STDOUT: !members:
  448. // CHECK:STDOUT: .Self = file.%import_ref.2
  449. // CHECK:STDOUT: .Equal = file.%import_ref.3
  450. // CHECK:STDOUT: .NotEqual = file.%import_ref.4
  451. // CHECK:STDOUT: witness = (file.%import_ref.5, file.%import_ref.6)
  452. // CHECK:STDOUT: }
  453. // CHECK:STDOUT:
  454. // CHECK:STDOUT: impl @impl: C as Eq {
  455. // CHECK:STDOUT: %Equal.decl: Equal = fn_decl @Equal.1 [template = constants.%struct.1] {
  456. // CHECK:STDOUT: %C.ref.loc10_18: type = name_ref C, file.%C.decl [template = constants.%C]
  457. // CHECK:STDOUT: %self.loc10_12.1: C = param self
  458. // CHECK:STDOUT: %self.loc10_12.2: C = bind_name self, %self.loc10_12.1
  459. // CHECK:STDOUT: %C.ref.loc10_28: type = name_ref C, file.%C.decl [template = constants.%C]
  460. // CHECK:STDOUT: %other.loc10_21.1: C = param other
  461. // CHECK:STDOUT: %other.loc10_21.2: C = bind_name other, %other.loc10_21.1
  462. // CHECK:STDOUT: %return.var.loc10: ref bool = var <return slot>
  463. // CHECK:STDOUT: }
  464. // CHECK:STDOUT: %NotEqual.decl: NotEqual = fn_decl @NotEqual.1 [template = constants.%struct.2] {
  465. // CHECK:STDOUT: %C.ref.loc11_21: type = name_ref C, file.%C.decl [template = constants.%C]
  466. // CHECK:STDOUT: %self.loc11_15.1: C = param self
  467. // CHECK:STDOUT: %self.loc11_15.2: C = bind_name self, %self.loc11_15.1
  468. // CHECK:STDOUT: %C.ref.loc11_31: type = name_ref C, file.%C.decl [template = constants.%C]
  469. // CHECK:STDOUT: %other.loc11_24.1: C = param other
  470. // CHECK:STDOUT: %other.loc11_24.2: C = bind_name other, %other.loc11_24.1
  471. // CHECK:STDOUT: %return.var.loc11: ref bool = var <return slot>
  472. // CHECK:STDOUT: }
  473. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Equal.decl, %NotEqual.decl) [template = constants.%.4]
  474. // CHECK:STDOUT:
  475. // CHECK:STDOUT: !members:
  476. // CHECK:STDOUT: .Equal = %Equal.decl
  477. // CHECK:STDOUT: .NotEqual = %NotEqual.decl
  478. // CHECK:STDOUT: witness = %.1
  479. // CHECK:STDOUT: }
  480. // CHECK:STDOUT:
  481. // CHECK:STDOUT: class @C {
  482. // CHECK:STDOUT: !members:
  483. // CHECK:STDOUT: .Self = constants.%C
  484. // CHECK:STDOUT: }
  485. // CHECK:STDOUT:
  486. // CHECK:STDOUT: class @D {
  487. // CHECK:STDOUT: !members:
  488. // CHECK:STDOUT: .Self = constants.%D
  489. // CHECK:STDOUT: }
  490. // CHECK:STDOUT:
  491. // CHECK:STDOUT: fn @Equal.1[@impl.%self.loc10_12.2: C](@impl.%other.loc10_21.2: C) -> bool;
  492. // CHECK:STDOUT:
  493. // CHECK:STDOUT: fn @NotEqual.1[@impl.%self.loc11_15.2: C](@impl.%other.loc11_24.2: C) -> bool;
  494. // CHECK:STDOUT:
  495. // CHECK:STDOUT: fn @Equal.2[%self: Self](%other: Self) -> bool;
  496. // CHECK:STDOUT:
  497. // CHECK:STDOUT: fn @NotEqual.2[%self: Self](%other: Self) -> bool;
  498. // CHECK:STDOUT:
  499. // CHECK:STDOUT: fn @TestRhsBad(%a: C, %b: D) -> bool {
  500. // CHECK:STDOUT: !entry:
  501. // CHECK:STDOUT: %a.ref: C = name_ref a, %a
  502. // CHECK:STDOUT: %b.ref: D = name_ref b, %b
  503. // CHECK:STDOUT: %.1: Equal = interface_witness_access @impl.%.1, element0 [template = constants.%struct.1]
  504. // CHECK:STDOUT: %.loc22_12: <bound method> = bound_method %a.ref, %.1
  505. // CHECK:STDOUT: %Equal.call: init bool = call %.loc22_12(<invalid>) [template = <error>]
  506. // CHECK:STDOUT: %.loc22_16.1: bool = value_of_initializer %Equal.call [template = <error>]
  507. // CHECK:STDOUT: %.loc22_16.2: bool = converted %Equal.call, %.loc22_16.1 [template = <error>]
  508. // CHECK:STDOUT: return %.loc22_16.2
  509. // CHECK:STDOUT: }
  510. // CHECK:STDOUT:
  511. // CHECK:STDOUT: fn @TestLhsBad(%a: D, %b: C) -> bool {
  512. // CHECK:STDOUT: !entry:
  513. // CHECK:STDOUT: %a.ref: D = name_ref a, %a
  514. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  515. // CHECK:STDOUT: return <error>
  516. // CHECK:STDOUT: }
  517. // CHECK:STDOUT: