eq.carbon 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/operators/overloaded/eq.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/eq.carbon
  10. // --- user.carbon
  11. package User;
  12. class C {};
  13. impl C as Core.Eq {
  14. fn Equal[self: C](other: C) -> bool;
  15. fn NotEqual[self: C](other: C) -> bool;
  16. }
  17. fn TestEqual(a: C, b: C) -> bool {
  18. return a == b;
  19. }
  20. fn TestNotEqual(a: C, b: C) -> bool {
  21. return a != b;
  22. }
  23. // --- fail_no_impl.carbon
  24. package FailNoImpl;
  25. class D {};
  26. fn TestEqual(a: D, b: D) -> bool {
  27. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.Eq` in type `D` that does not implement that interface [MissingImplInMemberAccess]
  28. // CHECK:STDERR: return a == b;
  29. // CHECK:STDERR: ^~~~~~
  30. // CHECK:STDERR:
  31. return a == b;
  32. }
  33. fn TestNotEqual(a: D, b: D) -> bool {
  34. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.Eq` in type `D` that does not implement that interface [MissingImplInMemberAccess]
  35. // CHECK:STDERR: return a != b;
  36. // CHECK:STDERR: ^~~~~~
  37. // CHECK:STDERR:
  38. return a != b;
  39. }
  40. // --- fail_no_impl_for_args.carbon
  41. package FailNoImplForArgs;
  42. class C {};
  43. class D {};
  44. impl C as Core.Eq {
  45. fn Equal[self: C](other: C) -> bool;
  46. fn NotEqual[self: C](other: C) -> bool;
  47. }
  48. fn TestRhsBad(a: C, b: D) -> bool {
  49. // CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE+10]]:15: error: cannot implicitly convert from `D` to `C` [ImplicitAsConversionFailure]
  50. // CHECK:STDERR: return a == b;
  51. // CHECK:STDERR: ^
  52. // CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE+7]]:15: note: type `D` does not implement interface `Core.ImplicitAs(C)` [MissingImplInMemberAccessNote]
  53. // CHECK:STDERR: return a == b;
  54. // CHECK:STDERR: ^
  55. // CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE-11]]:21: note: initializing function parameter [InCallToFunctionParam]
  56. // CHECK:STDERR: fn Equal[self: C](other: C) -> bool;
  57. // CHECK:STDERR: ^~~~~~~~
  58. // CHECK:STDERR:
  59. return a == b;
  60. }
  61. fn TestLhsBad(a: D, b: C) -> bool {
  62. // CHECK:STDERR: fail_no_impl_for_args.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.Eq` in type `D` that does not implement that interface [MissingImplInMemberAccess]
  63. // CHECK:STDERR: return a != b;
  64. // CHECK:STDERR: ^~~~~~
  65. // CHECK:STDERR:
  66. return a != b;
  67. }
  68. // CHECK:STDOUT: --- user.carbon
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: constants {
  71. // CHECK:STDOUT: %C: type = class_type @C [template]
  72. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  73. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  74. // CHECK:STDOUT: %Eq.type: type = facet_type <@Eq> [template]
  75. // CHECK:STDOUT: %Equal.type.79c: type = fn_type @Equal.1 [template]
  76. // CHECK:STDOUT: %NotEqual.type.e6c: type = fn_type @NotEqual.1 [template]
  77. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (@impl.1.%Equal.decl, @impl.1.%NotEqual.decl) [template]
  78. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  79. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  80. // CHECK:STDOUT: %Equal.type.b4a: type = fn_type @Equal.2 [template]
  81. // CHECK:STDOUT: %Equal.f96: %Equal.type.b4a = struct_value () [template]
  82. // CHECK:STDOUT: %NotEqual.type.a7d: type = fn_type @NotEqual.2 [template]
  83. // CHECK:STDOUT: %NotEqual.c3f: %NotEqual.type.a7d = struct_value () [template]
  84. // CHECK:STDOUT: %Eq.facet: %Eq.type = facet_value %C, %impl_witness [template]
  85. // CHECK:STDOUT: %TestEqual.type: type = fn_type @TestEqual [template]
  86. // CHECK:STDOUT: %TestEqual: %TestEqual.type = struct_value () [template]
  87. // CHECK:STDOUT: %.dad: type = fn_type_with_self_type %Equal.type.79c, %Eq.facet [template]
  88. // CHECK:STDOUT: %TestNotEqual.type: type = fn_type @TestNotEqual [template]
  89. // CHECK:STDOUT: %TestNotEqual: %TestNotEqual.type = struct_value () [template]
  90. // CHECK:STDOUT: %.d23: type = fn_type_with_self_type %NotEqual.type.e6c, %Eq.facet [template]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: imports {
  94. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  95. // CHECK:STDOUT: .Eq = %Core.Eq
  96. // CHECK:STDOUT: .Bool = %Core.Bool
  97. // CHECK:STDOUT: import Core//prelude
  98. // CHECK:STDOUT: import Core//prelude/...
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: %Core.Eq: type = import_ref Core//prelude/operators/comparison, Eq, loaded [template = constants.%Eq.type]
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: file {
  104. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  105. // CHECK:STDOUT: .Core = imports.%Core
  106. // CHECK:STDOUT: .C = %C.decl
  107. // CHECK:STDOUT: .TestEqual = %TestEqual.decl
  108. // CHECK:STDOUT: .TestNotEqual = %TestNotEqual.decl
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: %Core.import = import Core
  111. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  112. // CHECK:STDOUT: impl_decl @impl.1 [template] {} {
  113. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  114. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  115. // CHECK:STDOUT: %Eq.ref: type = name_ref Eq, imports.%Core.Eq [template = constants.%Eq.type]
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (@impl.1.%Equal.decl, @impl.1.%NotEqual.decl) [template = constants.%impl_witness]
  118. // CHECK:STDOUT: %TestEqual.decl: %TestEqual.type = fn_decl @TestEqual [template = constants.%TestEqual] {
  119. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  120. // CHECK:STDOUT: %a.param_patt: %C = value_param_pattern %a.patt, runtime_param0
  121. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  122. // CHECK:STDOUT: %b.param_patt: %C = value_param_pattern %b.patt, runtime_param1
  123. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  124. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  125. // CHECK:STDOUT: } {
  126. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  127. // CHECK:STDOUT: %.loc11_29.1: type = value_of_initializer %bool.make_type [template = bool]
  128. // CHECK:STDOUT: %.loc11_29.2: type = converted %bool.make_type, %.loc11_29.1 [template = bool]
  129. // CHECK:STDOUT: %a.param: %C = value_param runtime_param0
  130. // CHECK:STDOUT: %C.ref.loc11_17: type = name_ref C, file.%C.decl [template = constants.%C]
  131. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  132. // CHECK:STDOUT: %b.param: %C = value_param runtime_param1
  133. // CHECK:STDOUT: %C.ref.loc11_23: type = name_ref C, file.%C.decl [template = constants.%C]
  134. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  135. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  136. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: %TestNotEqual.decl: %TestNotEqual.type = fn_decl @TestNotEqual [template = constants.%TestNotEqual] {
  139. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  140. // CHECK:STDOUT: %a.param_patt: %C = value_param_pattern %a.patt, runtime_param0
  141. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  142. // CHECK:STDOUT: %b.param_patt: %C = value_param_pattern %b.patt, runtime_param1
  143. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  144. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  145. // CHECK:STDOUT: } {
  146. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  147. // CHECK:STDOUT: %.loc15_32.1: type = value_of_initializer %bool.make_type [template = bool]
  148. // CHECK:STDOUT: %.loc15_32.2: type = converted %bool.make_type, %.loc15_32.1 [template = bool]
  149. // CHECK:STDOUT: %a.param: %C = value_param runtime_param0
  150. // CHECK:STDOUT: %C.ref.loc15_20: type = name_ref C, file.%C.decl [template = constants.%C]
  151. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  152. // CHECK:STDOUT: %b.param: %C = value_param runtime_param1
  153. // CHECK:STDOUT: %C.ref.loc15_26: type = name_ref C, file.%C.decl [template = constants.%C]
  154. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  155. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  156. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: impl @impl.1: %C.ref as %Eq.ref {
  161. // CHECK:STDOUT: %Equal.decl: %Equal.type.b4a = fn_decl @Equal.2 [template = constants.%Equal.f96] {
  162. // CHECK:STDOUT: %self.patt: %C = binding_pattern self
  163. // CHECK:STDOUT: %self.param_patt: %C = value_param_pattern %self.patt, runtime_param0
  164. // CHECK:STDOUT: %other.patt: %C = binding_pattern other
  165. // CHECK:STDOUT: %other.param_patt: %C = value_param_pattern %other.patt, runtime_param1
  166. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  167. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  168. // CHECK:STDOUT: } {
  169. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  170. // CHECK:STDOUT: %.loc7_34.1: type = value_of_initializer %bool.make_type [template = bool]
  171. // CHECK:STDOUT: %.loc7_34.2: type = converted %bool.make_type, %.loc7_34.1 [template = bool]
  172. // CHECK:STDOUT: %self.param: %C = value_param runtime_param0
  173. // CHECK:STDOUT: %C.ref.loc7_18: type = name_ref C, file.%C.decl [template = constants.%C]
  174. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  175. // CHECK:STDOUT: %other.param: %C = value_param runtime_param1
  176. // CHECK:STDOUT: %C.ref.loc7_28: type = name_ref C, file.%C.decl [template = constants.%C]
  177. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  178. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  179. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT: %NotEqual.decl: %NotEqual.type.a7d = fn_decl @NotEqual.2 [template = constants.%NotEqual.c3f] {
  182. // CHECK:STDOUT: %self.patt: %C = binding_pattern self
  183. // CHECK:STDOUT: %self.param_patt: %C = value_param_pattern %self.patt, runtime_param0
  184. // CHECK:STDOUT: %other.patt: %C = binding_pattern other
  185. // CHECK:STDOUT: %other.param_patt: %C = value_param_pattern %other.patt, runtime_param1
  186. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  187. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  188. // CHECK:STDOUT: } {
  189. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  190. // CHECK:STDOUT: %.loc8_37.1: type = value_of_initializer %bool.make_type [template = bool]
  191. // CHECK:STDOUT: %.loc8_37.2: type = converted %bool.make_type, %.loc8_37.1 [template = bool]
  192. // CHECK:STDOUT: %self.param: %C = value_param runtime_param0
  193. // CHECK:STDOUT: %C.ref.loc8_21: type = name_ref C, file.%C.decl [template = constants.%C]
  194. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  195. // CHECK:STDOUT: %other.param: %C = value_param runtime_param1
  196. // CHECK:STDOUT: %C.ref.loc8_31: type = name_ref C, file.%C.decl [template = constants.%C]
  197. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  198. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  199. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: !members:
  203. // CHECK:STDOUT: .Equal = %Equal.decl
  204. // CHECK:STDOUT: .NotEqual = %NotEqual.decl
  205. // CHECK:STDOUT: witness = file.%impl_witness
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: class @C {
  209. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  210. // CHECK:STDOUT: complete_type_witness = %complete_type
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: !members:
  213. // CHECK:STDOUT: .Self = constants.%C
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT:
  216. // CHECK:STDOUT: fn @Equal.2[%self.param_patt: %C](%other.param_patt: %C) -> bool;
  217. // CHECK:STDOUT:
  218. // CHECK:STDOUT: fn @NotEqual.2[%self.param_patt: %C](%other.param_patt: %C) -> bool;
  219. // CHECK:STDOUT:
  220. // CHECK:STDOUT: fn @TestEqual(%a.param_patt: %C, %b.param_patt: %C) -> bool {
  221. // CHECK:STDOUT: !entry:
  222. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  223. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  224. // CHECK:STDOUT: %impl.elem0: %.dad = impl_witness_access constants.%impl_witness, element0 [template = constants.%Equal.f96]
  225. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
  226. // CHECK:STDOUT: %Equal.call: init bool = call %bound_method(%a.ref, %b.ref)
  227. // CHECK:STDOUT: %.loc12_16.1: bool = value_of_initializer %Equal.call
  228. // CHECK:STDOUT: %.loc12_16.2: bool = converted %Equal.call, %.loc12_16.1
  229. // CHECK:STDOUT: return %.loc12_16.2
  230. // CHECK:STDOUT: }
  231. // CHECK:STDOUT:
  232. // CHECK:STDOUT: fn @TestNotEqual(%a.param_patt: %C, %b.param_patt: %C) -> bool {
  233. // CHECK:STDOUT: !entry:
  234. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  235. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  236. // CHECK:STDOUT: %impl.elem1: %.d23 = impl_witness_access constants.%impl_witness, element1 [template = constants.%NotEqual.c3f]
  237. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem1
  238. // CHECK:STDOUT: %NotEqual.call: init bool = call %bound_method(%a.ref, %b.ref)
  239. // CHECK:STDOUT: %.loc16_16.1: bool = value_of_initializer %NotEqual.call
  240. // CHECK:STDOUT: %.loc16_16.2: bool = converted %NotEqual.call, %.loc16_16.1
  241. // CHECK:STDOUT: return %.loc16_16.2
  242. // CHECK:STDOUT: }
  243. // CHECK:STDOUT:
  244. // CHECK:STDOUT: --- fail_no_impl.carbon
  245. // CHECK:STDOUT:
  246. // CHECK:STDOUT: constants {
  247. // CHECK:STDOUT: %D: type = class_type @D [template]
  248. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  249. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  250. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  251. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  252. // CHECK:STDOUT: %TestEqual.type: type = fn_type @TestEqual [template]
  253. // CHECK:STDOUT: %TestEqual: %TestEqual.type = struct_value () [template]
  254. // CHECK:STDOUT: %TestNotEqual.type: type = fn_type @TestNotEqual [template]
  255. // CHECK:STDOUT: %TestNotEqual: %TestNotEqual.type = struct_value () [template]
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT:
  258. // CHECK:STDOUT: imports {
  259. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  260. // CHECK:STDOUT: .Bool = %Core.Bool
  261. // CHECK:STDOUT: .Eq = %Core.Eq
  262. // CHECK:STDOUT: import Core//prelude
  263. // CHECK:STDOUT: import Core//prelude/...
  264. // CHECK:STDOUT: }
  265. // CHECK:STDOUT: }
  266. // CHECK:STDOUT:
  267. // CHECK:STDOUT: file {
  268. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  269. // CHECK:STDOUT: .Core = imports.%Core
  270. // CHECK:STDOUT: .D = %D.decl
  271. // CHECK:STDOUT: .TestEqual = %TestEqual.decl
  272. // CHECK:STDOUT: .TestNotEqual = %TestNotEqual.decl
  273. // CHECK:STDOUT: }
  274. // CHECK:STDOUT: %Core.import = import Core
  275. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  276. // CHECK:STDOUT: %TestEqual.decl: %TestEqual.type = fn_decl @TestEqual [template = constants.%TestEqual] {
  277. // CHECK:STDOUT: %a.patt: %D = binding_pattern a
  278. // CHECK:STDOUT: %a.param_patt: %D = value_param_pattern %a.patt, runtime_param0
  279. // CHECK:STDOUT: %b.patt: %D = binding_pattern b
  280. // CHECK:STDOUT: %b.param_patt: %D = value_param_pattern %b.patt, runtime_param1
  281. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  282. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  283. // CHECK:STDOUT: } {
  284. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  285. // CHECK:STDOUT: %.loc6_29.1: type = value_of_initializer %bool.make_type [template = bool]
  286. // CHECK:STDOUT: %.loc6_29.2: type = converted %bool.make_type, %.loc6_29.1 [template = bool]
  287. // CHECK:STDOUT: %a.param: %D = value_param runtime_param0
  288. // CHECK:STDOUT: %D.ref.loc6_17: type = name_ref D, file.%D.decl [template = constants.%D]
  289. // CHECK:STDOUT: %a: %D = bind_name a, %a.param
  290. // CHECK:STDOUT: %b.param: %D = value_param runtime_param1
  291. // CHECK:STDOUT: %D.ref.loc6_23: type = name_ref D, file.%D.decl [template = constants.%D]
  292. // CHECK:STDOUT: %b: %D = bind_name b, %b.param
  293. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  294. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  295. // CHECK:STDOUT: }
  296. // CHECK:STDOUT: %TestNotEqual.decl: %TestNotEqual.type = fn_decl @TestNotEqual [template = constants.%TestNotEqual] {
  297. // CHECK:STDOUT: %a.patt: %D = binding_pattern a
  298. // CHECK:STDOUT: %a.param_patt: %D = value_param_pattern %a.patt, runtime_param0
  299. // CHECK:STDOUT: %b.patt: %D = binding_pattern b
  300. // CHECK:STDOUT: %b.param_patt: %D = value_param_pattern %b.patt, runtime_param1
  301. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  302. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  303. // CHECK:STDOUT: } {
  304. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  305. // CHECK:STDOUT: %.loc14_32.1: type = value_of_initializer %bool.make_type [template = bool]
  306. // CHECK:STDOUT: %.loc14_32.2: type = converted %bool.make_type, %.loc14_32.1 [template = bool]
  307. // CHECK:STDOUT: %a.param: %D = value_param runtime_param0
  308. // CHECK:STDOUT: %D.ref.loc14_20: type = name_ref D, file.%D.decl [template = constants.%D]
  309. // CHECK:STDOUT: %a: %D = bind_name a, %a.param
  310. // CHECK:STDOUT: %b.param: %D = value_param runtime_param1
  311. // CHECK:STDOUT: %D.ref.loc14_26: type = name_ref D, file.%D.decl [template = constants.%D]
  312. // CHECK:STDOUT: %b: %D = bind_name b, %b.param
  313. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  314. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  315. // CHECK:STDOUT: }
  316. // CHECK:STDOUT: }
  317. // CHECK:STDOUT:
  318. // CHECK:STDOUT: class @D {
  319. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  320. // CHECK:STDOUT: complete_type_witness = %complete_type
  321. // CHECK:STDOUT:
  322. // CHECK:STDOUT: !members:
  323. // CHECK:STDOUT: .Self = constants.%D
  324. // CHECK:STDOUT: }
  325. // CHECK:STDOUT:
  326. // CHECK:STDOUT: fn @TestEqual(%a.param_patt: %D, %b.param_patt: %D) -> bool {
  327. // CHECK:STDOUT: !entry:
  328. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  329. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  330. // CHECK:STDOUT: return <error>
  331. // CHECK:STDOUT: }
  332. // CHECK:STDOUT:
  333. // CHECK:STDOUT: fn @TestNotEqual(%a.param_patt: %D, %b.param_patt: %D) -> bool {
  334. // CHECK:STDOUT: !entry:
  335. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  336. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  337. // CHECK:STDOUT: return <error>
  338. // CHECK:STDOUT: }
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: --- fail_no_impl_for_args.carbon
  341. // CHECK:STDOUT:
  342. // CHECK:STDOUT: constants {
  343. // CHECK:STDOUT: %C: type = class_type @C [template]
  344. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  345. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  346. // CHECK:STDOUT: %D: type = class_type @D [template]
  347. // CHECK:STDOUT: %Eq.type: type = facet_type <@Eq> [template]
  348. // CHECK:STDOUT: %Equal.type.79c: type = fn_type @Equal.1 [template]
  349. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (@impl.1.%Equal.decl, @impl.1.%NotEqual.decl) [template]
  350. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  351. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  352. // CHECK:STDOUT: %Equal.type.b4a: type = fn_type @Equal.2 [template]
  353. // CHECK:STDOUT: %Equal.f96: %Equal.type.b4a = struct_value () [template]
  354. // CHECK:STDOUT: %NotEqual.type.a7d: type = fn_type @NotEqual.2 [template]
  355. // CHECK:STDOUT: %NotEqual.c3f: %NotEqual.type.a7d = struct_value () [template]
  356. // CHECK:STDOUT: %Eq.facet: %Eq.type = facet_value %C, %impl_witness [template]
  357. // CHECK:STDOUT: %TestRhsBad.type: type = fn_type @TestRhsBad [template]
  358. // CHECK:STDOUT: %TestRhsBad: %TestRhsBad.type = struct_value () [template]
  359. // CHECK:STDOUT: %.dad: type = fn_type_with_self_type %Equal.type.79c, %Eq.facet [template]
  360. // CHECK:STDOUT: %TestLhsBad.type: type = fn_type @TestLhsBad [template]
  361. // CHECK:STDOUT: %TestLhsBad: %TestLhsBad.type = struct_value () [template]
  362. // CHECK:STDOUT: }
  363. // CHECK:STDOUT:
  364. // CHECK:STDOUT: imports {
  365. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  366. // CHECK:STDOUT: .Eq = %Core.Eq
  367. // CHECK:STDOUT: .Bool = %Core.Bool
  368. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  369. // CHECK:STDOUT: import Core//prelude
  370. // CHECK:STDOUT: import Core//prelude/...
  371. // CHECK:STDOUT: }
  372. // CHECK:STDOUT: %Core.Eq: type = import_ref Core//prelude/operators/comparison, Eq, loaded [template = constants.%Eq.type]
  373. // CHECK:STDOUT: }
  374. // CHECK:STDOUT:
  375. // CHECK:STDOUT: file {
  376. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  377. // CHECK:STDOUT: .Core = imports.%Core
  378. // CHECK:STDOUT: .C = %C.decl
  379. // CHECK:STDOUT: .D = %D.decl
  380. // CHECK:STDOUT: .TestRhsBad = %TestRhsBad.decl
  381. // CHECK:STDOUT: .TestLhsBad = %TestLhsBad.decl
  382. // CHECK:STDOUT: }
  383. // CHECK:STDOUT: %Core.import = import Core
  384. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  385. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  386. // CHECK:STDOUT: impl_decl @impl.1 [template] {} {
  387. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  388. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  389. // CHECK:STDOUT: %Eq.ref: type = name_ref Eq, imports.%Core.Eq [template = constants.%Eq.type]
  390. // CHECK:STDOUT: }
  391. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (@impl.1.%Equal.decl, @impl.1.%NotEqual.decl) [template = constants.%impl_witness]
  392. // CHECK:STDOUT: %TestRhsBad.decl: %TestRhsBad.type = fn_decl @TestRhsBad [template = constants.%TestRhsBad] {
  393. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  394. // CHECK:STDOUT: %a.param_patt: %C = value_param_pattern %a.patt, runtime_param0
  395. // CHECK:STDOUT: %b.patt: %D = binding_pattern b
  396. // CHECK:STDOUT: %b.param_patt: %D = value_param_pattern %b.patt, runtime_param1
  397. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  398. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  399. // CHECK:STDOUT: } {
  400. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  401. // CHECK:STDOUT: %.loc12_30.1: type = value_of_initializer %bool.make_type [template = bool]
  402. // CHECK:STDOUT: %.loc12_30.2: type = converted %bool.make_type, %.loc12_30.1 [template = bool]
  403. // CHECK:STDOUT: %a.param: %C = value_param runtime_param0
  404. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  405. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  406. // CHECK:STDOUT: %b.param: %D = value_param runtime_param1
  407. // CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [template = constants.%D]
  408. // CHECK:STDOUT: %b: %D = bind_name b, %b.param
  409. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  410. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  411. // CHECK:STDOUT: }
  412. // CHECK:STDOUT: %TestLhsBad.decl: %TestLhsBad.type = fn_decl @TestLhsBad [template = constants.%TestLhsBad] {
  413. // CHECK:STDOUT: %a.patt: %D = binding_pattern a
  414. // CHECK:STDOUT: %a.param_patt: %D = value_param_pattern %a.patt, runtime_param0
  415. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  416. // CHECK:STDOUT: %b.param_patt: %C = value_param_pattern %b.patt, runtime_param1
  417. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  418. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  419. // CHECK:STDOUT: } {
  420. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  421. // CHECK:STDOUT: %.loc26_30.1: type = value_of_initializer %bool.make_type [template = bool]
  422. // CHECK:STDOUT: %.loc26_30.2: type = converted %bool.make_type, %.loc26_30.1 [template = bool]
  423. // CHECK:STDOUT: %a.param: %D = value_param runtime_param0
  424. // CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [template = constants.%D]
  425. // CHECK:STDOUT: %a: %D = bind_name a, %a.param
  426. // CHECK:STDOUT: %b.param: %C = value_param runtime_param1
  427. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  428. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  429. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  430. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  431. // CHECK:STDOUT: }
  432. // CHECK:STDOUT: }
  433. // CHECK:STDOUT:
  434. // CHECK:STDOUT: impl @impl.1: %C.ref as %Eq.ref {
  435. // CHECK:STDOUT: %Equal.decl: %Equal.type.b4a = fn_decl @Equal.2 [template = constants.%Equal.f96] {
  436. // CHECK:STDOUT: %self.patt: %C = binding_pattern self
  437. // CHECK:STDOUT: %self.param_patt: %C = value_param_pattern %self.patt, runtime_param0
  438. // CHECK:STDOUT: %other.patt: %C = binding_pattern other
  439. // CHECK:STDOUT: %other.param_patt: %C = value_param_pattern %other.patt, runtime_param1
  440. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  441. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  442. // CHECK:STDOUT: } {
  443. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  444. // CHECK:STDOUT: %.loc8_34.1: type = value_of_initializer %bool.make_type [template = bool]
  445. // CHECK:STDOUT: %.loc8_34.2: type = converted %bool.make_type, %.loc8_34.1 [template = bool]
  446. // CHECK:STDOUT: %self.param: %C = value_param runtime_param0
  447. // CHECK:STDOUT: %C.ref.loc8_18: type = name_ref C, file.%C.decl [template = constants.%C]
  448. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  449. // CHECK:STDOUT: %other.param: %C = value_param runtime_param1
  450. // CHECK:STDOUT: %C.ref.loc8_28: type = name_ref C, file.%C.decl [template = constants.%C]
  451. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  452. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  453. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  454. // CHECK:STDOUT: }
  455. // CHECK:STDOUT: %NotEqual.decl: %NotEqual.type.a7d = fn_decl @NotEqual.2 [template = constants.%NotEqual.c3f] {
  456. // CHECK:STDOUT: %self.patt: %C = binding_pattern self
  457. // CHECK:STDOUT: %self.param_patt: %C = value_param_pattern %self.patt, runtime_param0
  458. // CHECK:STDOUT: %other.patt: %C = binding_pattern other
  459. // CHECK:STDOUT: %other.param_patt: %C = value_param_pattern %other.patt, runtime_param1
  460. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  461. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  462. // CHECK:STDOUT: } {
  463. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  464. // CHECK:STDOUT: %.loc9_37.1: type = value_of_initializer %bool.make_type [template = bool]
  465. // CHECK:STDOUT: %.loc9_37.2: type = converted %bool.make_type, %.loc9_37.1 [template = bool]
  466. // CHECK:STDOUT: %self.param: %C = value_param runtime_param0
  467. // CHECK:STDOUT: %C.ref.loc9_21: type = name_ref C, file.%C.decl [template = constants.%C]
  468. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  469. // CHECK:STDOUT: %other.param: %C = value_param runtime_param1
  470. // CHECK:STDOUT: %C.ref.loc9_31: type = name_ref C, file.%C.decl [template = constants.%C]
  471. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  472. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  473. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  474. // CHECK:STDOUT: }
  475. // CHECK:STDOUT:
  476. // CHECK:STDOUT: !members:
  477. // CHECK:STDOUT: .Equal = %Equal.decl
  478. // CHECK:STDOUT: .NotEqual = %NotEqual.decl
  479. // CHECK:STDOUT: witness = file.%impl_witness
  480. // CHECK:STDOUT: }
  481. // CHECK:STDOUT:
  482. // CHECK:STDOUT: class @C {
  483. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  484. // CHECK:STDOUT: complete_type_witness = %complete_type
  485. // CHECK:STDOUT:
  486. // CHECK:STDOUT: !members:
  487. // CHECK:STDOUT: .Self = constants.%C
  488. // CHECK:STDOUT: }
  489. // CHECK:STDOUT:
  490. // CHECK:STDOUT: class @D {
  491. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  492. // CHECK:STDOUT: complete_type_witness = %complete_type
  493. // CHECK:STDOUT:
  494. // CHECK:STDOUT: !members:
  495. // CHECK:STDOUT: .Self = constants.%D
  496. // CHECK:STDOUT: }
  497. // CHECK:STDOUT:
  498. // CHECK:STDOUT: fn @Equal.2[%self.param_patt: %C](%other.param_patt: %C) -> bool;
  499. // CHECK:STDOUT:
  500. // CHECK:STDOUT: fn @NotEqual.2[%self.param_patt: %C](%other.param_patt: %C) -> bool;
  501. // CHECK:STDOUT:
  502. // CHECK:STDOUT: fn @TestRhsBad(%a.param_patt: %C, %b.param_patt: %D) -> bool {
  503. // CHECK:STDOUT: !entry:
  504. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  505. // CHECK:STDOUT: %b.ref: %D = name_ref b, %b
  506. // CHECK:STDOUT: %impl.elem0: %.dad = impl_witness_access constants.%impl_witness, element0 [template = constants.%Equal.f96]
  507. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
  508. // CHECK:STDOUT: %.loc23_15: %C = converted %b.ref, <error> [template = <error>]
  509. // CHECK:STDOUT: %Equal.call: init bool = call %bound_method(%a.ref, <error>)
  510. // CHECK:STDOUT: %.loc23_16.1: bool = value_of_initializer %Equal.call
  511. // CHECK:STDOUT: %.loc23_16.2: bool = converted %Equal.call, %.loc23_16.1
  512. // CHECK:STDOUT: return %.loc23_16.2
  513. // CHECK:STDOUT: }
  514. // CHECK:STDOUT:
  515. // CHECK:STDOUT: fn @TestLhsBad(%a.param_patt: %D, %b.param_patt: %C) -> bool {
  516. // CHECK:STDOUT: !entry:
  517. // CHECK:STDOUT: %a.ref: %D = name_ref a, %a
  518. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  519. // CHECK:STDOUT: return <error>
  520. // CHECK:STDOUT: }
  521. // CHECK:STDOUT: