eq.carbon 24 KB

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