fail_no_impl.carbon 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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/fail_no_impl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/fail_no_impl.carbon
  10. package User;
  11. class C {};
  12. fn TestUnary(a: C) -> C {
  13. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Negate` in type `C` that does not implement that interface
  14. // CHECK:STDERR: return -a;
  15. // CHECK:STDERR: ^~
  16. // CHECK:STDERR:
  17. return -a;
  18. }
  19. fn TestBinary(a: C, b: C) -> C {
  20. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Add` in type `C` that does not implement that interface
  21. // CHECK:STDERR: return a + b;
  22. // CHECK:STDERR: ^~~~~
  23. // CHECK:STDERR:
  24. return a + b;
  25. }
  26. fn TestRef(b: C) {
  27. var a: C = {};
  28. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:3: error: cannot access member of interface `AddAssign` in type `C` that does not implement that interface
  29. // CHECK:STDERR: a += b;
  30. // CHECK:STDERR: ^~~~~~
  31. // CHECK:STDERR:
  32. a += b;
  33. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+3]]:3: error: cannot access member of interface `Inc` in type `C` that does not implement that interface
  34. // CHECK:STDERR: ++a;
  35. // CHECK:STDERR: ^~~
  36. ++a;
  37. }
  38. // CHECK:STDOUT: --- fail_no_impl.carbon
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: constants {
  41. // CHECK:STDOUT: %C: type = class_type @C [template]
  42. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  43. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  44. // CHECK:STDOUT: %TestUnary.type: type = fn_type @TestUnary [template]
  45. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  46. // CHECK:STDOUT: %TestUnary: %TestUnary.type = struct_value () [template]
  47. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  48. // CHECK:STDOUT: %Negate.type: type = interface_type @Negate [template]
  49. // CHECK:STDOUT: %Self.1: %Negate.type = bind_symbolic_name Self, 0 [symbolic]
  50. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1 [template]
  51. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [template]
  52. // CHECK:STDOUT: %.5: type = assoc_entity_type %Negate.type, %Op.type.1 [template]
  53. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, imports.%import_ref.5 [template]
  54. // CHECK:STDOUT: %TestBinary.type: type = fn_type @TestBinary [template]
  55. // CHECK:STDOUT: %TestBinary: %TestBinary.type = struct_value () [template]
  56. // CHECK:STDOUT: %Add.type: type = interface_type @Add [template]
  57. // CHECK:STDOUT: %Self.2: %Add.type = bind_symbolic_name Self, 0 [symbolic]
  58. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.2 [template]
  59. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  60. // CHECK:STDOUT: %.7: type = assoc_entity_type %Add.type, %Op.type.2 [template]
  61. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.10 [template]
  62. // CHECK:STDOUT: %TestRef.type: type = fn_type @TestRef [template]
  63. // CHECK:STDOUT: %TestRef: %TestRef.type = struct_value () [template]
  64. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  65. // CHECK:STDOUT: %AddAssign.type: type = interface_type @AddAssign [template]
  66. // CHECK:STDOUT: %Self.3: %AddAssign.type = bind_symbolic_name Self, 0 [symbolic]
  67. // CHECK:STDOUT: %Op.type.3: type = fn_type @Op.3 [template]
  68. // CHECK:STDOUT: %Op.3: %Op.type.3 = struct_value () [template]
  69. // CHECK:STDOUT: %.9: type = ptr_type %Self.3 [symbolic]
  70. // CHECK:STDOUT: %.10: type = assoc_entity_type %AddAssign.type, %Op.type.3 [template]
  71. // CHECK:STDOUT: %.11: %.10 = assoc_entity element0, imports.%import_ref.15 [template]
  72. // CHECK:STDOUT: %Inc.type: type = interface_type @Inc [template]
  73. // CHECK:STDOUT: %Self.4: %Inc.type = bind_symbolic_name Self, 0 [symbolic]
  74. // CHECK:STDOUT: %Op.type.4: type = fn_type @Op.4 [template]
  75. // CHECK:STDOUT: %Op.4: %Op.type.4 = struct_value () [template]
  76. // CHECK:STDOUT: %.12: type = ptr_type %Self.4 [symbolic]
  77. // CHECK:STDOUT: %.13: type = assoc_entity_type %Inc.type, %Op.type.4 [template]
  78. // CHECK:STDOUT: %.14: %.13 = assoc_entity element0, imports.%import_ref.20 [template]
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: imports {
  82. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  83. // CHECK:STDOUT: .Negate = %import_ref.1
  84. // CHECK:STDOUT: .Add = %import_ref.6
  85. // CHECK:STDOUT: .AddAssign = %import_ref.11
  86. // CHECK:STDOUT: .Inc = %import_ref.16
  87. // CHECK:STDOUT: import Core//prelude
  88. // CHECK:STDOUT: import Core//prelude/operators
  89. // CHECK:STDOUT: import Core//prelude/types
  90. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  91. // CHECK:STDOUT: import Core//prelude/operators/as
  92. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  93. // CHECK:STDOUT: import Core//prelude/operators/comparison
  94. // CHECK:STDOUT: import Core//prelude/types/bool
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %import_ref.1: type = import_ref Core//prelude/operators/arithmetic, inst+82, loaded [template = constants.%Negate.type]
  97. // CHECK:STDOUT: %import_ref.2 = import_ref Core//prelude/operators/arithmetic, inst+84, unloaded
  98. // CHECK:STDOUT: %import_ref.3: %.5 = import_ref Core//prelude/operators/arithmetic, inst+102, loaded [template = constants.%.6]
  99. // CHECK:STDOUT: %import_ref.4 = import_ref Core//prelude/operators/arithmetic, inst+97, unloaded
  100. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/arithmetic, inst+97, unloaded
  101. // CHECK:STDOUT: %import_ref.6: type = import_ref Core//prelude/operators/arithmetic, inst+1, loaded [template = constants.%Add.type]
  102. // CHECK:STDOUT: %import_ref.7 = import_ref Core//prelude/operators/arithmetic, inst+3, unloaded
  103. // CHECK:STDOUT: %import_ref.8: %.7 = import_ref Core//prelude/operators/arithmetic, inst+29, loaded [template = constants.%.8]
  104. // CHECK:STDOUT: %import_ref.9 = import_ref Core//prelude/operators/arithmetic, inst+23, unloaded
  105. // CHECK:STDOUT: %import_ref.10 = import_ref Core//prelude/operators/arithmetic, inst+23, unloaded
  106. // CHECK:STDOUT: %import_ref.11: type = import_ref Core//prelude/operators/arithmetic, inst+31, loaded [template = constants.%AddAssign.type]
  107. // CHECK:STDOUT: %import_ref.12 = import_ref Core//prelude/operators/arithmetic, inst+33, unloaded
  108. // CHECK:STDOUT: %import_ref.13: %.10 = import_ref Core//prelude/operators/arithmetic, inst+58, loaded [template = constants.%.11]
  109. // CHECK:STDOUT: %import_ref.14 = import_ref Core//prelude/operators/arithmetic, inst+52, unloaded
  110. // CHECK:STDOUT: %import_ref.15 = import_ref Core//prelude/operators/arithmetic, inst+52, unloaded
  111. // CHECK:STDOUT: %import_ref.16: type = import_ref Core//prelude/operators/arithmetic, inst+60, loaded [template = constants.%Inc.type]
  112. // CHECK:STDOUT: %import_ref.17 = import_ref Core//prelude/operators/arithmetic, inst+62, unloaded
  113. // CHECK:STDOUT: %import_ref.18: %.13 = import_ref Core//prelude/operators/arithmetic, inst+80, loaded [template = constants.%.14]
  114. // CHECK:STDOUT: %import_ref.19 = import_ref Core//prelude/operators/arithmetic, inst+74, unloaded
  115. // CHECK:STDOUT: %import_ref.20 = import_ref Core//prelude/operators/arithmetic, inst+74, unloaded
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: file {
  119. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  120. // CHECK:STDOUT: .Core = imports.%Core
  121. // CHECK:STDOUT: .C = %C.decl
  122. // CHECK:STDOUT: .TestUnary = %TestUnary.decl
  123. // CHECK:STDOUT: .TestBinary = %TestBinary.decl
  124. // CHECK:STDOUT: .TestRef = %TestRef.decl
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %Core.import = import Core
  127. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  128. // CHECK:STDOUT: %TestUnary.decl: %TestUnary.type = fn_decl @TestUnary [template = constants.%TestUnary] {
  129. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  130. // CHECK:STDOUT: %a.param_patt: %C = param_pattern %a.patt, runtime_param0
  131. // CHECK:STDOUT: } {
  132. // CHECK:STDOUT: %C.ref.loc15_17: type = name_ref C, file.%C.decl [template = constants.%C]
  133. // CHECK:STDOUT: %C.ref.loc15_23: type = name_ref C, file.%C.decl [template = constants.%C]
  134. // CHECK:STDOUT: %return: ref %C = var <return slot>
  135. // CHECK:STDOUT: %param: %C = param runtime_param0
  136. // CHECK:STDOUT: %a: %C = bind_name a, %param
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: %TestBinary.decl: %TestBinary.type = fn_decl @TestBinary [template = constants.%TestBinary] {
  139. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  140. // CHECK:STDOUT: %a.param_patt: %C = param_pattern %a.patt, runtime_param0
  141. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  142. // CHECK:STDOUT: %b.param_patt: %C = param_pattern %b.patt, runtime_param1
  143. // CHECK:STDOUT: } {
  144. // CHECK:STDOUT: %C.ref.loc23_18: type = name_ref C, file.%C.decl [template = constants.%C]
  145. // CHECK:STDOUT: %C.ref.loc23_24: type = name_ref C, file.%C.decl [template = constants.%C]
  146. // CHECK:STDOUT: %C.ref.loc23_30: type = name_ref C, file.%C.decl [template = constants.%C]
  147. // CHECK:STDOUT: %return: ref %C = var <return slot>
  148. // CHECK:STDOUT: %param.loc23_15: %C = param runtime_param0
  149. // CHECK:STDOUT: %a: %C = bind_name a, %param.loc23_15
  150. // CHECK:STDOUT: %param.loc23_21: %C = param runtime_param1
  151. // CHECK:STDOUT: %b: %C = bind_name b, %param.loc23_21
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT: %TestRef.decl: %TestRef.type = fn_decl @TestRef [template = constants.%TestRef] {
  154. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  155. // CHECK:STDOUT: %b.param_patt: %C = param_pattern %b.patt, runtime_param0
  156. // CHECK:STDOUT: } {
  157. // CHECK:STDOUT: %C.ref.loc31: type = name_ref C, file.%C.decl [template = constants.%C]
  158. // CHECK:STDOUT: %param: %C = param runtime_param0
  159. // CHECK:STDOUT: %b: %C = bind_name b, %param
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: interface @Negate {
  164. // CHECK:STDOUT: !members:
  165. // CHECK:STDOUT: .Self = imports.%import_ref.2
  166. // CHECK:STDOUT: .Op = imports.%import_ref.3
  167. // CHECK:STDOUT: witness = (imports.%import_ref.4)
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: interface @Add {
  171. // CHECK:STDOUT: !members:
  172. // CHECK:STDOUT: .Self = imports.%import_ref.7
  173. // CHECK:STDOUT: .Op = imports.%import_ref.8
  174. // CHECK:STDOUT: witness = (imports.%import_ref.9)
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: interface @AddAssign {
  178. // CHECK:STDOUT: !members:
  179. // CHECK:STDOUT: .Self = imports.%import_ref.12
  180. // CHECK:STDOUT: .Op = imports.%import_ref.13
  181. // CHECK:STDOUT: witness = (imports.%import_ref.14)
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: interface @Inc {
  185. // CHECK:STDOUT: !members:
  186. // CHECK:STDOUT: .Self = imports.%import_ref.17
  187. // CHECK:STDOUT: .Op = imports.%import_ref.18
  188. // CHECK:STDOUT: witness = (imports.%import_ref.19)
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: class @C {
  192. // CHECK:STDOUT: %.loc13: <witness> = complete_type_witness %.1 [template = constants.%.2]
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: !members:
  195. // CHECK:STDOUT: .Self = constants.%C
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: fn @TestUnary(%a.param_patt: %C) -> %return: %C {
  199. // CHECK:STDOUT: !entry:
  200. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  201. // CHECK:STDOUT: %Op.ref: %.5 = name_ref Op, imports.%import_ref.3 [template = constants.%.6]
  202. // CHECK:STDOUT: return <error> to %return
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: generic fn @Op.1(constants.%Self.1: %Negate.type) {
  206. // CHECK:STDOUT: %Self: %Negate.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self.1)]
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: fn[%self.param_patt: @Op.1.%Self (%Self.1)]() -> @Op.1.%Self (%Self.1);
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: fn @TestBinary(%a.param_patt: %C, %b.param_patt: %C) -> %return: %C {
  212. // CHECK:STDOUT: !entry:
  213. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  214. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  215. // CHECK:STDOUT: %Op.ref: %.7 = name_ref Op, imports.%import_ref.8 [template = constants.%.8]
  216. // CHECK:STDOUT: return <error> to %return
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: generic fn @Op.2(constants.%Self.2: %Add.type) {
  220. // CHECK:STDOUT: %Self: %Add.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self.2)]
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: fn[%self.param_patt: @Op.2.%Self (%Self.2)](%other.param_patt: @Op.2.%Self (%Self.2)) -> @Op.2.%Self (%Self.2);
  223. // CHECK:STDOUT: }
  224. // CHECK:STDOUT:
  225. // CHECK:STDOUT: fn @TestRef(%b.param_patt: %C) {
  226. // CHECK:STDOUT: !entry:
  227. // CHECK:STDOUT: %C.ref.loc32: type = name_ref C, file.%C.decl [template = constants.%C]
  228. // CHECK:STDOUT: %a.var: ref %C = var a
  229. // CHECK:STDOUT: %a: ref %C = bind_name a, %a.var
  230. // CHECK:STDOUT: %.loc32_15.1: %.1 = struct_literal ()
  231. // CHECK:STDOUT: %.loc32_15.2: init %C = class_init (), %a.var [template = constants.%struct]
  232. // CHECK:STDOUT: %.loc32_16: init %C = converted %.loc32_15.1, %.loc32_15.2 [template = constants.%struct]
  233. // CHECK:STDOUT: assign %a.var, %.loc32_16
  234. // CHECK:STDOUT: %a.ref.loc37: ref %C = name_ref a, %a
  235. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  236. // CHECK:STDOUT: %Op.ref.loc37: %.10 = name_ref Op, imports.%import_ref.13 [template = constants.%.11]
  237. // CHECK:STDOUT: %a.ref.loc41: ref %C = name_ref a, %a
  238. // CHECK:STDOUT: %Op.ref.loc41: %.13 = name_ref Op, imports.%import_ref.18 [template = constants.%.14]
  239. // CHECK:STDOUT: return
  240. // CHECK:STDOUT: }
  241. // CHECK:STDOUT:
  242. // CHECK:STDOUT: generic fn @Op.3(constants.%Self.3: %AddAssign.type) {
  243. // CHECK:STDOUT: %Self: %AddAssign.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self.3)]
  244. // CHECK:STDOUT: %.2: type = ptr_type @Op.3.%Self (%Self.3) [symbolic = %.2 (constants.%.9)]
  245. // CHECK:STDOUT:
  246. // CHECK:STDOUT: fn[addr <unexpected>.inst+116: @Op.3.%.2 (%.9)](%other.param_patt: @Op.3.%Self (%Self.3));
  247. // CHECK:STDOUT: }
  248. // CHECK:STDOUT:
  249. // CHECK:STDOUT: generic fn @Op.4(constants.%Self.4: %Inc.type) {
  250. // CHECK:STDOUT: %Self: %Inc.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self.4)]
  251. // CHECK:STDOUT: %.2: type = ptr_type @Op.4.%Self (%Self.4) [symbolic = %.2 (constants.%.12)]
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: fn[addr <unexpected>.inst+143: @Op.4.%.2 (%.12)]();
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: specific @Op.1(constants.%Self.1) {
  257. // CHECK:STDOUT: %Self => constants.%Self.1
  258. // CHECK:STDOUT: }
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: specific @Op.2(constants.%Self.2) {
  261. // CHECK:STDOUT: %Self => constants.%Self.2
  262. // CHECK:STDOUT: }
  263. // CHECK:STDOUT:
  264. // CHECK:STDOUT: specific @Op.3(constants.%Self.3) {
  265. // CHECK:STDOUT: %Self => constants.%Self.3
  266. // CHECK:STDOUT: %.2 => constants.%.9
  267. // CHECK:STDOUT: }
  268. // CHECK:STDOUT:
  269. // CHECK:STDOUT: specific @Op.4(constants.%Self.4) {
  270. // CHECK:STDOUT: %Self => constants.%Self.4
  271. // CHECK:STDOUT: %.2 => constants.%.12
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT: