fail_no_impl.carbon 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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: %TestUnary.type: type = fn_type @TestUnary [template]
  44. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  45. // CHECK:STDOUT: %TestUnary: %TestUnary.type = struct_value () [template]
  46. // CHECK:STDOUT: %.3: type = ptr_type %.1 [template]
  47. // CHECK:STDOUT: %.4: type = interface_type @Negate [template]
  48. // CHECK:STDOUT: %Self.1: %.4 = bind_symbolic_name Self 0 [symbolic]
  49. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1 [template]
  50. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [template]
  51. // CHECK:STDOUT: %.5: type = assoc_entity_type @Negate, %Op.type.1 [template]
  52. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, file.%import_ref.5 [template]
  53. // CHECK:STDOUT: %TestBinary.type: type = fn_type @TestBinary [template]
  54. // CHECK:STDOUT: %TestBinary: %TestBinary.type = struct_value () [template]
  55. // CHECK:STDOUT: %.7: type = interface_type @Add [template]
  56. // CHECK:STDOUT: %Self.2: %.7 = bind_symbolic_name Self 0 [symbolic]
  57. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.2 [template]
  58. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  59. // CHECK:STDOUT: %.8: type = assoc_entity_type @Add, %Op.type.2 [template]
  60. // CHECK:STDOUT: %.9: %.8 = assoc_entity element0, file.%import_ref.10 [template]
  61. // CHECK:STDOUT: %TestRef.type: type = fn_type @TestRef [template]
  62. // CHECK:STDOUT: %TestRef: %TestRef.type = struct_value () [template]
  63. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  64. // CHECK:STDOUT: %.10: type = interface_type @AddAssign [template]
  65. // CHECK:STDOUT: %Self.3: %.10 = bind_symbolic_name Self 0 [symbolic]
  66. // CHECK:STDOUT: %.11: type = ptr_type %Self.3 [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: %.12: type = assoc_entity_type @AddAssign, %Op.type.3 [template]
  70. // CHECK:STDOUT: %.13: %.12 = assoc_entity element0, file.%import_ref.15 [template]
  71. // CHECK:STDOUT: %.14: type = interface_type @Inc [template]
  72. // CHECK:STDOUT: %Self.4: %.14 = bind_symbolic_name Self 0 [symbolic]
  73. // CHECK:STDOUT: %.15: type = ptr_type %Self.4 [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: %.16: type = assoc_entity_type @Inc, %Op.type.4 [template]
  77. // CHECK:STDOUT: %.17: %.16 = assoc_entity element0, file.%import_ref.20 [template]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: file {
  81. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  82. // CHECK:STDOUT: .Core = %Core
  83. // CHECK:STDOUT: .C = %C.decl
  84. // CHECK:STDOUT: .TestUnary = %TestUnary.decl
  85. // CHECK:STDOUT: .TestBinary = %TestBinary.decl
  86. // CHECK:STDOUT: .TestRef = %TestRef.decl
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  89. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  90. // CHECK:STDOUT: %TestUnary.decl: %TestUnary.type = fn_decl @TestUnary [template = constants.%TestUnary] {
  91. // CHECK:STDOUT: %C.ref.loc15_17: type = name_ref C, %C.decl [template = constants.%C]
  92. // CHECK:STDOUT: %a.loc15_14.1: %C = param a
  93. // CHECK:STDOUT: @TestUnary.%a: %C = bind_name a, %a.loc15_14.1
  94. // CHECK:STDOUT: %C.ref.loc15_23: type = name_ref C, %C.decl [template = constants.%C]
  95. // CHECK:STDOUT: @TestUnary.%return: ref %C = var <return slot>
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %import_ref.1: type = import_ref ir4, inst+67, loaded [template = constants.%.4]
  98. // CHECK:STDOUT: %import_ref.2 = import_ref ir4, inst+69, unloaded
  99. // CHECK:STDOUT: %import_ref.3: %.5 = import_ref ir4, inst+84, loaded [template = constants.%.6]
  100. // CHECK:STDOUT: %import_ref.4 = import_ref ir4, inst+80, unloaded
  101. // CHECK:STDOUT: %import_ref.5 = import_ref ir4, inst+80, unloaded
  102. // CHECK:STDOUT: %TestBinary.decl: %TestBinary.type = fn_decl @TestBinary [template = constants.%TestBinary] {
  103. // CHECK:STDOUT: %C.ref.loc23_18: type = name_ref C, %C.decl [template = constants.%C]
  104. // CHECK:STDOUT: %a.loc23_15.1: %C = param a
  105. // CHECK:STDOUT: @TestBinary.%a: %C = bind_name a, %a.loc23_15.1
  106. // CHECK:STDOUT: %C.ref.loc23_24: type = name_ref C, %C.decl [template = constants.%C]
  107. // CHECK:STDOUT: %b.loc23_21.1: %C = param b
  108. // CHECK:STDOUT: @TestBinary.%b: %C = bind_name b, %b.loc23_21.1
  109. // CHECK:STDOUT: %C.ref.loc23_30: type = name_ref C, %C.decl [template = constants.%C]
  110. // CHECK:STDOUT: @TestBinary.%return: ref %C = var <return slot>
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: %import_ref.6: type = import_ref ir4, inst+1, loaded [template = constants.%.7]
  113. // CHECK:STDOUT: %import_ref.7 = import_ref ir4, inst+3, unloaded
  114. // CHECK:STDOUT: %import_ref.8: %.8 = import_ref ir4, inst+24, loaded [template = constants.%.9]
  115. // CHECK:STDOUT: %import_ref.9 = import_ref ir4, inst+19, unloaded
  116. // CHECK:STDOUT: %import_ref.10 = import_ref ir4, inst+19, unloaded
  117. // CHECK:STDOUT: %TestRef.decl: %TestRef.type = fn_decl @TestRef [template = constants.%TestRef] {
  118. // CHECK:STDOUT: %C.ref.loc31: type = name_ref C, %C.decl [template = constants.%C]
  119. // CHECK:STDOUT: %b.loc31_12.1: %C = param b
  120. // CHECK:STDOUT: @TestRef.%b: %C = bind_name b, %b.loc31_12.1
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %import_ref.11: type = import_ref ir4, inst+26, loaded [template = constants.%.10]
  123. // CHECK:STDOUT: %import_ref.12 = import_ref ir4, inst+28, unloaded
  124. // CHECK:STDOUT: %import_ref.13: %.12 = import_ref ir4, inst+47, loaded [template = constants.%.13]
  125. // CHECK:STDOUT: %import_ref.14 = import_ref ir4, inst+43, unloaded
  126. // CHECK:STDOUT: %import_ref.15 = import_ref ir4, inst+43, unloaded
  127. // CHECK:STDOUT: %import_ref.16: type = import_ref ir4, inst+49, loaded [template = constants.%.14]
  128. // CHECK:STDOUT: %import_ref.17 = import_ref ir4, inst+51, unloaded
  129. // CHECK:STDOUT: %import_ref.18: %.16 = import_ref ir4, inst+65, loaded [template = constants.%.17]
  130. // CHECK:STDOUT: %import_ref.19 = import_ref ir4, inst+61, unloaded
  131. // CHECK:STDOUT: %import_ref.20 = import_ref ir4, inst+61, unloaded
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: interface @Negate {
  135. // CHECK:STDOUT: !members:
  136. // CHECK:STDOUT: .Self = file.%import_ref.2
  137. // CHECK:STDOUT: .Op = file.%import_ref.3
  138. // CHECK:STDOUT: witness = (file.%import_ref.4)
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: interface @Add {
  142. // CHECK:STDOUT: !members:
  143. // CHECK:STDOUT: .Self = file.%import_ref.7
  144. // CHECK:STDOUT: .Op = file.%import_ref.8
  145. // CHECK:STDOUT: witness = (file.%import_ref.9)
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: interface @AddAssign {
  149. // CHECK:STDOUT: !members:
  150. // CHECK:STDOUT: .Self = file.%import_ref.12
  151. // CHECK:STDOUT: .Op = file.%import_ref.13
  152. // CHECK:STDOUT: witness = (file.%import_ref.14)
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: interface @Inc {
  156. // CHECK:STDOUT: !members:
  157. // CHECK:STDOUT: .Self = file.%import_ref.17
  158. // CHECK:STDOUT: .Op = file.%import_ref.18
  159. // CHECK:STDOUT: witness = (file.%import_ref.19)
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: class @C {
  163. // CHECK:STDOUT: !members:
  164. // CHECK:STDOUT: .Self = constants.%C
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: fn @TestUnary(%a: %C) -> %return: %C {
  168. // CHECK:STDOUT: !entry:
  169. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  170. // CHECK:STDOUT: return <error> to %return
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: fn @Op.1[%self: %Self.1]() -> %Self.1;
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: fn @TestBinary(%a: %C, %b: %C) -> %return: %C {
  176. // CHECK:STDOUT: !entry:
  177. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  178. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  179. // CHECK:STDOUT: return <error> to %return
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: fn @Op.2[%self: %Self.2](%other: %Self.2) -> %Self.2;
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: fn @TestRef(%b: %C) {
  185. // CHECK:STDOUT: !entry:
  186. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  187. // CHECK:STDOUT: %a.var: ref %C = var a
  188. // CHECK:STDOUT: %a: ref %C = bind_name a, %a.var
  189. // CHECK:STDOUT: %.loc32_15.1: %.1 = struct_literal ()
  190. // CHECK:STDOUT: %.loc32_15.2: init %C = class_init (), %a.var [template = constants.%struct]
  191. // CHECK:STDOUT: %.loc32_16: init %C = converted %.loc32_15.1, %.loc32_15.2 [template = constants.%struct]
  192. // CHECK:STDOUT: assign %a.var, %.loc32_16
  193. // CHECK:STDOUT: %a.ref.loc37: ref %C = name_ref a, %a
  194. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  195. // CHECK:STDOUT: %a.ref.loc41: ref %C = name_ref a, %a
  196. // CHECK:STDOUT: return
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: fn @Op.3[addr %self: %.11](%other: %Self.3);
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: fn @Op.4[addr %self: %.15]();
  202. // CHECK:STDOUT: