eq.carbon 33 KB

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