eq.carbon 24 KB

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