fail_no_impl.carbon 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/operators/overloaded/fail_no_impl.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/fail_no_impl.carbon
  13. package User;
  14. class C {};
  15. fn TestUnary(a: C) -> C {
  16. // 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]
  17. // CHECK:STDERR: return -a;
  18. // CHECK:STDERR: ^~
  19. // CHECK:STDERR:
  20. return -a;
  21. }
  22. fn TestBinary(a: C, b: C) -> C {
  23. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:10: error: cannot access member of interface `Core.Add` in type `C` that does not implement that interface [MissingImplInMemberAccess]
  24. // CHECK:STDERR: return a + b;
  25. // CHECK:STDERR: ^~~~~
  26. // CHECK:STDERR:
  27. return a + b;
  28. }
  29. fn TestRef(b: C) {
  30. var a: C = {};
  31. // CHECK:STDERR: fail_no_impl.carbon:[[@LINE+4]]:3: error: cannot access member of interface `Core.AddAssign` in type `C` that does not implement that interface [MissingImplInMemberAccess]
  32. // CHECK:STDERR: a += b;
  33. // CHECK:STDERR: ^~~~~~
  34. // CHECK:STDERR:
  35. a += b;
  36. // 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]
  37. // CHECK:STDERR: ++a;
  38. // CHECK:STDERR: ^~~
  39. // CHECK:STDERR:
  40. ++a;
  41. }
  42. // CHECK:STDOUT: --- fail_no_impl.carbon
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: constants {
  45. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  46. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  47. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  48. // CHECK:STDOUT: %pattern_type.c48: type = pattern_type %C [concrete]
  49. // CHECK:STDOUT: %TestUnary.type: type = fn_type @TestUnary [concrete]
  50. // CHECK:STDOUT: %TestUnary: %TestUnary.type = struct_value () [concrete]
  51. // CHECK:STDOUT: %Negate.type: type = facet_type <@Negate> [concrete]
  52. // CHECK:STDOUT: %Add.type: type = facet_type <@Add> [concrete]
  53. // CHECK:STDOUT: %TestBinary.type: type = fn_type @TestBinary [concrete]
  54. // CHECK:STDOUT: %TestBinary: %TestBinary.type = struct_value () [concrete]
  55. // CHECK:STDOUT: %TestRef.type: type = fn_type @TestRef [concrete]
  56. // CHECK:STDOUT: %TestRef: %TestRef.type = struct_value () [concrete]
  57. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  58. // CHECK:STDOUT: %AddAssign.type: type = facet_type <@AddAssign> [concrete]
  59. // CHECK:STDOUT: %Inc.type: type = facet_type <@Inc> [concrete]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: imports {
  63. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  64. // CHECK:STDOUT: .Negate = %Core.Negate
  65. // CHECK:STDOUT: .Add = %Core.Add
  66. // CHECK:STDOUT: .AddAssign = %Core.AddAssign
  67. // CHECK:STDOUT: .Inc = %Core.Inc
  68. // CHECK:STDOUT: import Core//prelude
  69. // CHECK:STDOUT: import Core//prelude/...
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Core.Negate: type = import_ref Core//prelude/operators/arithmetic, Negate, loaded [concrete = constants.%Negate.type]
  72. // CHECK:STDOUT: %Core.Add: type = import_ref Core//prelude/operators/arithmetic, Add, loaded [concrete = constants.%Add.type]
  73. // CHECK:STDOUT: %Core.AddAssign: type = import_ref Core//prelude/operators/arithmetic, AddAssign, loaded [concrete = constants.%AddAssign.type]
  74. // CHECK:STDOUT: %Core.Inc: type = import_ref Core//prelude/operators/arithmetic, Inc, loaded [concrete = constants.%Inc.type]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: file {
  78. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  79. // CHECK:STDOUT: .Core = imports.%Core
  80. // CHECK:STDOUT: .C = %C.decl
  81. // CHECK:STDOUT: .TestUnary = %TestUnary.decl
  82. // CHECK:STDOUT: .TestBinary = %TestBinary.decl
  83. // CHECK:STDOUT: .TestRef = %TestRef.decl
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: %Core.import = import Core
  86. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  87. // CHECK:STDOUT: %TestUnary.decl: %TestUnary.type = fn_decl @TestUnary [concrete = constants.%TestUnary] {
  88. // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
  89. // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
  90. // CHECK:STDOUT: %return.patt: %pattern_type.c48 = return_slot_pattern [concrete]
  91. // CHECK:STDOUT: %return.param_patt: %pattern_type.c48 = out_param_pattern %return.patt, call_param1 [concrete]
  92. // CHECK:STDOUT: } {
  93. // CHECK:STDOUT: %C.ref.loc18_23: type = name_ref C, file.%C.decl [concrete = constants.%C]
  94. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  95. // CHECK:STDOUT: %C.ref.loc18_17: type = name_ref C, file.%C.decl [concrete = constants.%C]
  96. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  97. // CHECK:STDOUT: %return.param: ref %C = out_param call_param1
  98. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: %TestBinary.decl: %TestBinary.type = fn_decl @TestBinary [concrete = constants.%TestBinary] {
  101. // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
  102. // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
  103. // CHECK:STDOUT: %b.patt: %pattern_type.c48 = binding_pattern b [concrete]
  104. // CHECK:STDOUT: %b.param_patt: %pattern_type.c48 = value_param_pattern %b.patt, call_param1 [concrete]
  105. // CHECK:STDOUT: %return.patt: %pattern_type.c48 = return_slot_pattern [concrete]
  106. // CHECK:STDOUT: %return.param_patt: %pattern_type.c48 = out_param_pattern %return.patt, call_param2 [concrete]
  107. // CHECK:STDOUT: } {
  108. // CHECK:STDOUT: %C.ref.loc26_30: type = name_ref C, file.%C.decl [concrete = constants.%C]
  109. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  110. // CHECK:STDOUT: %C.ref.loc26_18: type = name_ref C, file.%C.decl [concrete = constants.%C]
  111. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  112. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  113. // CHECK:STDOUT: %C.ref.loc26_24: type = name_ref C, file.%C.decl [concrete = constants.%C]
  114. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  115. // CHECK:STDOUT: %return.param: ref %C = out_param call_param2
  116. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: %TestRef.decl: %TestRef.type = fn_decl @TestRef [concrete = constants.%TestRef] {
  119. // CHECK:STDOUT: %b.patt: %pattern_type.c48 = binding_pattern b [concrete]
  120. // CHECK:STDOUT: %b.param_patt: %pattern_type.c48 = value_param_pattern %b.patt, call_param0 [concrete]
  121. // CHECK:STDOUT: } {
  122. // CHECK:STDOUT: %b.param: %C = value_param call_param0
  123. // CHECK:STDOUT: %C.ref.loc34: type = name_ref C, file.%C.decl [concrete = constants.%C]
  124. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: class @C {
  129. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  130. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  131. // CHECK:STDOUT: complete_type_witness = %complete_type
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: !members:
  134. // CHECK:STDOUT: .Self = constants.%C
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: fn @TestUnary(%a.param: %C) -> %return.param: %C {
  138. // CHECK:STDOUT: !entry:
  139. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  140. // CHECK:STDOUT: return <error> to %return
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: fn @TestBinary(%a.param: %C, %b.param: %C) -> %return.param: %C {
  144. // CHECK:STDOUT: !entry:
  145. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  146. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  147. // CHECK:STDOUT: return <error> to %return
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: fn @TestRef(%b.param: %C) {
  151. // CHECK:STDOUT: !entry:
  152. // CHECK:STDOUT: name_binding_decl {
  153. // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
  154. // CHECK:STDOUT: %a.var_patt: %pattern_type.c48 = var_pattern %a.patt [concrete]
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT: %a.var: ref %C = var %a.var_patt
  157. // CHECK:STDOUT: %.loc35_15.1: %empty_struct_type = struct_literal ()
  158. // CHECK:STDOUT: %.loc35_15.2: init %C = class_init (), %a.var [concrete = constants.%C.val]
  159. // CHECK:STDOUT: %.loc35_3: init %C = converted %.loc35_15.1, %.loc35_15.2 [concrete = constants.%C.val]
  160. // CHECK:STDOUT: assign %a.var, %.loc35_3
  161. // CHECK:STDOUT: %C.ref.loc35: type = name_ref C, file.%C.decl [concrete = constants.%C]
  162. // CHECK:STDOUT: %a: ref %C = bind_name a, %a.var
  163. // CHECK:STDOUT: %a.ref.loc40: ref %C = name_ref a, %a
  164. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  165. // CHECK:STDOUT: %a.ref.loc45: ref %C = name_ref a, %a
  166. // CHECK:STDOUT: return
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: