fail_no_impl.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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/fail_no_impl.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/fail_no_impl.carbon
  14. package User;
  15. class C {};
  16. fn TestUnary(a: C) -> C {
  17. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.Negate` in type `C` that does not implement that interface [MissingImplInMemberAccess]
  18. // CHECK:STDERR: return -a;
  19. // CHECK:STDERR: ^~
  20. // CHECK:STDERR:
  21. return -a;
  22. }
  23. fn TestBinary(a: C, b: C) -> C {
  24. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.AddWith(C)` in type `C` that does not implement that interface [MissingImplInMemberAccess]
  25. // CHECK:STDERR: return a + b;
  26. // CHECK:STDERR: ^~~~~
  27. // CHECK:STDERR:
  28. return a + b;
  29. }
  30. fn TestRef(b: C) {
  31. var a: C = {};
  32. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:3: error: cannot access member of interface `Core.AddAssignWith(C)` in type `C` that does not implement that interface [MissingImplInMemberAccess]
  33. // CHECK:STDERR: a += b;
  34. // CHECK:STDERR: ^~~~~~
  35. // CHECK:STDERR:
  36. a += b;
  37. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:3: error: cannot access member of interface `Core.Inc` in type `C` that does not implement that interface [MissingImplInMemberAccess]
  38. // CHECK:STDERR: ++a;
  39. // CHECK:STDERR: ^~~
  40. // CHECK:STDERR:
  41. ++a;
  42. }
  43. // CHECK:STDOUT: --- fail_no_impl.carbon
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: constants {
  46. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  47. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  48. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  49. // CHECK:STDOUT: %pattern_type.476: type = pattern_type %C [concrete]
  50. // CHECK:STDOUT: %.c0e: form = init_form %C, call_param1 [concrete]
  51. // CHECK:STDOUT: %TestUnary.type: type = fn_type @TestUnary [concrete]
  52. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  53. // CHECK:STDOUT: %TestUnary: %TestUnary.type = struct_value () [concrete]
  54. // CHECK:STDOUT: %Negate.type: type = facet_type <@Negate> [concrete]
  55. // CHECK:STDOUT: %.099: form = init_form %C, call_param2 [concrete]
  56. // CHECK:STDOUT: %TestBinary.type: type = fn_type @TestBinary [concrete]
  57. // CHECK:STDOUT: %TestBinary: %TestBinary.type = struct_value () [concrete]
  58. // CHECK:STDOUT: %AddWith.type.e05: type = generic_interface_type @AddWith [concrete]
  59. // CHECK:STDOUT: %AddWith.generic: %AddWith.type.e05 = struct_value () [concrete]
  60. // CHECK:STDOUT: %TestRef.type: type = fn_type @TestRef [concrete]
  61. // CHECK:STDOUT: %TestRef: %TestRef.type = struct_value () [concrete]
  62. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  63. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  64. // CHECK:STDOUT: %AddAssignWith.type.fc6: type = generic_interface_type @AddAssignWith [concrete]
  65. // CHECK:STDOUT: %AddAssignWith.generic: %AddAssignWith.type.fc6 = struct_value () [concrete]
  66. // CHECK:STDOUT: %Inc.type: type = facet_type <@Inc> [concrete]
  67. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  68. // CHECK:STDOUT: %DestroyOp.type: type = fn_type @DestroyOp [concrete]
  69. // CHECK:STDOUT: %DestroyOp: %DestroyOp.type = struct_value () [concrete]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: imports {
  73. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  74. // CHECK:STDOUT: .Negate = %Core.Negate
  75. // CHECK:STDOUT: .AddWith = %Core.AddWith
  76. // CHECK:STDOUT: .AddAssignWith = %Core.AddAssignWith
  77. // CHECK:STDOUT: .Inc = %Core.Inc
  78. // CHECK:STDOUT: .Destroy = %Core.Destroy
  79. // CHECK:STDOUT: import Core//prelude
  80. // CHECK:STDOUT: import Core//prelude/...
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %Core.Negate: type = import_ref Core//prelude/operators/arithmetic, Negate, loaded [concrete = constants.%Negate.type]
  83. // CHECK:STDOUT: %Core.AddWith: %AddWith.type.e05 = import_ref Core//prelude/operators/arithmetic, AddWith, loaded [concrete = constants.%AddWith.generic]
  84. // CHECK:STDOUT: %Core.AddAssignWith: %AddAssignWith.type.fc6 = import_ref Core//prelude/operators/arithmetic, AddAssignWith, loaded [concrete = constants.%AddAssignWith.generic]
  85. // CHECK:STDOUT: %Core.Inc: type = import_ref Core//prelude/operators/arithmetic, Inc, loaded [concrete = constants.%Inc.type]
  86. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: file {
  90. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  91. // CHECK:STDOUT: .Core = imports.%Core
  92. // CHECK:STDOUT: .C = %C.decl
  93. // CHECK:STDOUT: .TestUnary = %TestUnary.decl
  94. // CHECK:STDOUT: .TestBinary = %TestBinary.decl
  95. // CHECK:STDOUT: .TestRef = %TestRef.decl
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %Core.import = import Core
  98. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  99. // CHECK:STDOUT: %TestUnary.decl: %TestUnary.type = fn_decl @TestUnary [concrete = constants.%TestUnary] {
  100. // CHECK:STDOUT: %a.patt: %pattern_type.476 = value_binding_pattern a [concrete]
  101. // CHECK:STDOUT: %a.param_patt: %pattern_type.476 = value_param_pattern %a.patt, call_param0 [concrete]
  102. // CHECK:STDOUT: %return.patt: %pattern_type.476 = return_slot_pattern [concrete]
  103. // CHECK:STDOUT: %return.param_patt: %pattern_type.476 = out_param_pattern %return.patt, call_param1 [concrete]
  104. // CHECK:STDOUT: } {
  105. // CHECK:STDOUT: %C.ref.loc19_23: type = name_ref C, file.%C.decl [concrete = constants.%C]
  106. // CHECK:STDOUT: %.loc19: form = init_form %C.ref.loc19_23, call_param1 [concrete = constants.%.c0e]
  107. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  108. // CHECK:STDOUT: %C.ref.loc19_17: type = name_ref C, file.%C.decl [concrete = constants.%C]
  109. // CHECK:STDOUT: %a: %C = value_binding a, %a.param
  110. // CHECK:STDOUT: %return.param: ref %C = out_param call_param1
  111. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %TestBinary.decl: %TestBinary.type = fn_decl @TestBinary [concrete = constants.%TestBinary] {
  114. // CHECK:STDOUT: %a.patt: %pattern_type.476 = value_binding_pattern a [concrete]
  115. // CHECK:STDOUT: %a.param_patt: %pattern_type.476 = value_param_pattern %a.patt, call_param0 [concrete]
  116. // CHECK:STDOUT: %b.patt: %pattern_type.476 = value_binding_pattern b [concrete]
  117. // CHECK:STDOUT: %b.param_patt: %pattern_type.476 = value_param_pattern %b.patt, call_param1 [concrete]
  118. // CHECK:STDOUT: %return.patt: %pattern_type.476 = return_slot_pattern [concrete]
  119. // CHECK:STDOUT: %return.param_patt: %pattern_type.476 = out_param_pattern %return.patt, call_param2 [concrete]
  120. // CHECK:STDOUT: } {
  121. // CHECK:STDOUT: %C.ref.loc27_30: type = name_ref C, file.%C.decl [concrete = constants.%C]
  122. // CHECK:STDOUT: %.loc27: form = init_form %C.ref.loc27_30, call_param2 [concrete = constants.%.099]
  123. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  124. // CHECK:STDOUT: %C.ref.loc27_18: type = name_ref C, file.%C.decl [concrete = constants.%C]
  125. // CHECK:STDOUT: %a: %C = value_binding a, %a.param
  126. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  127. // CHECK:STDOUT: %C.ref.loc27_24: type = name_ref C, file.%C.decl [concrete = constants.%C]
  128. // CHECK:STDOUT: %b: %C = value_binding b, %b.param
  129. // CHECK:STDOUT: %return.param: ref %C = out_param call_param2
  130. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: %TestRef.decl: %TestRef.type = fn_decl @TestRef [concrete = constants.%TestRef] {
  133. // CHECK:STDOUT: %b.patt: %pattern_type.476 = value_binding_pattern b [concrete]
  134. // CHECK:STDOUT: %b.param_patt: %pattern_type.476 = value_param_pattern %b.patt, call_param0 [concrete]
  135. // CHECK:STDOUT: } {
  136. // CHECK:STDOUT: %b.param: %C = value_param call_param0
  137. // CHECK:STDOUT: %C.ref.loc35: type = name_ref C, file.%C.decl [concrete = constants.%C]
  138. // CHECK:STDOUT: %b: %C = value_binding b, %b.param
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: class @C {
  143. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  144. // CHECK:STDOUT: complete_type_witness = %complete_type
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: !members:
  147. // CHECK:STDOUT: .Self = constants.%C
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: fn @TestUnary(%a.param: %C) -> %return.param: %C {
  151. // CHECK:STDOUT: !entry:
  152. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  153. // CHECK:STDOUT: return <error> to %return.param
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: fn @TestBinary(%a.param: %C, %b.param: %C) -> %return.param: %C {
  157. // CHECK:STDOUT: !entry:
  158. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  159. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  160. // CHECK:STDOUT: return <error> to %return.param
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: fn @TestRef(%b.param: %C) {
  164. // CHECK:STDOUT: !entry:
  165. // CHECK:STDOUT: name_binding_decl {
  166. // CHECK:STDOUT: %a.patt: %pattern_type.476 = ref_binding_pattern a [concrete]
  167. // CHECK:STDOUT: %a.var_patt: %pattern_type.476 = var_pattern %a.patt [concrete]
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: %a.var: ref %C = var %a.var_patt
  170. // CHECK:STDOUT: %.loc36_15.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  171. // CHECK:STDOUT: %.loc36_15.2: init %C = class_init (), %a.var [concrete = constants.%C.val]
  172. // CHECK:STDOUT: %.loc36_3: init %C = converted %.loc36_15.1, %.loc36_15.2 [concrete = constants.%C.val]
  173. // CHECK:STDOUT: assign %a.var, %.loc36_3
  174. // CHECK:STDOUT: %C.ref.loc36: type = name_ref C, file.%C.decl [concrete = constants.%C]
  175. // CHECK:STDOUT: %a: ref %C = ref_binding a, %a.var
  176. // CHECK:STDOUT: %a.ref.loc41: ref %C = name_ref a, %a
  177. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  178. // CHECK:STDOUT: %a.ref.loc46: ref %C = name_ref a, %a
  179. // CHECK:STDOUT: %DestroyOp.bound: <bound method> = bound_method %a.var, constants.%DestroyOp
  180. // CHECK:STDOUT: %DestroyOp.call: init %empty_tuple.type = call %DestroyOp.bound(%a.var)
  181. // CHECK:STDOUT: return
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: fn @DestroyOp(%self.param: %C) = "no_op";
  185. // CHECK:STDOUT: