fail_no_impl.carbon 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 `Core.Negate` in type `C` that does not implement that interface [MissingImplInMemberAccess]
  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 `Core.Add` in type `C` that does not implement that interface [MissingImplInMemberAccess]
  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 `Core.AddAssign` in type `C` that does not implement that interface [MissingImplInMemberAccess]
  29. // CHECK:STDERR: a += b;
  30. // CHECK:STDERR: ^~~~~~
  31. // CHECK:STDERR:
  32. a += b;
  33. // 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]
  34. // CHECK:STDERR: ++a;
  35. // CHECK:STDERR: ^~~
  36. // CHECK:STDERR:
  37. ++a;
  38. }
  39. // CHECK:STDOUT: --- fail_no_impl.carbon
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: constants {
  42. // CHECK:STDOUT: %C: type = class_type @C [template]
  43. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  44. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  45. // CHECK:STDOUT: %TestUnary.type: type = fn_type @TestUnary [template]
  46. // CHECK:STDOUT: %TestUnary: %TestUnary.type = struct_value () [template]
  47. // CHECK:STDOUT: %TestBinary.type: type = fn_type @TestBinary [template]
  48. // CHECK:STDOUT: %TestBinary: %TestBinary.type = struct_value () [template]
  49. // CHECK:STDOUT: %TestRef.type: type = fn_type @TestRef [template]
  50. // CHECK:STDOUT: %TestRef: %TestRef.type = struct_value () [template]
  51. // CHECK:STDOUT: %C.val: %C = struct_value () [template]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: imports {
  55. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  56. // CHECK:STDOUT: .Negate = %Core.Negate
  57. // CHECK:STDOUT: .Add = %Core.Add
  58. // CHECK:STDOUT: .AddAssign = %Core.AddAssign
  59. // CHECK:STDOUT: .Inc = %Core.Inc
  60. // CHECK:STDOUT: import Core//prelude
  61. // CHECK:STDOUT: import Core//prelude/...
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  67. // CHECK:STDOUT: .Core = imports.%Core
  68. // CHECK:STDOUT: .C = %C.decl
  69. // CHECK:STDOUT: .TestUnary = %TestUnary.decl
  70. // CHECK:STDOUT: .TestBinary = %TestBinary.decl
  71. // CHECK:STDOUT: .TestRef = %TestRef.decl
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %Core.import = import Core
  74. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  75. // CHECK:STDOUT: %TestUnary.decl: %TestUnary.type = fn_decl @TestUnary [template = constants.%TestUnary] {
  76. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  77. // CHECK:STDOUT: %a.param_patt: %C = value_param_pattern %a.patt, runtime_param0
  78. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  79. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, runtime_param1
  80. // CHECK:STDOUT: } {
  81. // CHECK:STDOUT: %C.ref.loc15_23: type = name_ref C, file.%C.decl [template = constants.%C]
  82. // CHECK:STDOUT: %a.param: %C = value_param runtime_param0
  83. // CHECK:STDOUT: %C.ref.loc15_17: type = name_ref C, file.%C.decl [template = constants.%C]
  84. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  85. // CHECK:STDOUT: %return.param: ref %C = out_param runtime_param1
  86. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %TestBinary.decl: %TestBinary.type = fn_decl @TestBinary [template = constants.%TestBinary] {
  89. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  90. // CHECK:STDOUT: %a.param_patt: %C = value_param_pattern %a.patt, runtime_param0
  91. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  92. // CHECK:STDOUT: %b.param_patt: %C = value_param_pattern %b.patt, runtime_param1
  93. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  94. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, runtime_param2
  95. // CHECK:STDOUT: } {
  96. // CHECK:STDOUT: %C.ref.loc23_30: type = name_ref C, file.%C.decl [template = constants.%C]
  97. // CHECK:STDOUT: %a.param: %C = value_param runtime_param0
  98. // CHECK:STDOUT: %C.ref.loc23_18: type = name_ref C, file.%C.decl [template = constants.%C]
  99. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  100. // CHECK:STDOUT: %b.param: %C = value_param runtime_param1
  101. // CHECK:STDOUT: %C.ref.loc23_24: type = name_ref C, file.%C.decl [template = constants.%C]
  102. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  103. // CHECK:STDOUT: %return.param: ref %C = out_param runtime_param2
  104. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %TestRef.decl: %TestRef.type = fn_decl @TestRef [template = constants.%TestRef] {
  107. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  108. // CHECK:STDOUT: %b.param_patt: %C = value_param_pattern %b.patt, runtime_param0
  109. // CHECK:STDOUT: } {
  110. // CHECK:STDOUT: %b.param: %C = value_param runtime_param0
  111. // CHECK:STDOUT: %C.ref.loc31: type = name_ref C, file.%C.decl [template = constants.%C]
  112. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: class @C {
  117. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  118. // CHECK:STDOUT: complete_type_witness = %complete_type
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: !members:
  121. // CHECK:STDOUT: .Self = constants.%C
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: fn @TestUnary(%a.param_patt: %C) -> %return.param_patt: %C {
  125. // CHECK:STDOUT: !entry:
  126. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  127. // CHECK:STDOUT: return <error> to %return
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: fn @TestBinary(%a.param_patt: %C, %b.param_patt: %C) -> %return.param_patt: %C {
  131. // CHECK:STDOUT: !entry:
  132. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  133. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  134. // CHECK:STDOUT: return <error> to %return
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: fn @TestRef(%b.param_patt: %C) {
  138. // CHECK:STDOUT: !entry:
  139. // CHECK:STDOUT: name_binding_decl {
  140. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  141. // CHECK:STDOUT: %.loc32_3.1: %C = var_pattern %a.patt
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %a.var: ref %C = var a
  144. // CHECK:STDOUT: %.loc32_15.1: %empty_struct_type = struct_literal ()
  145. // CHECK:STDOUT: %.loc32_15.2: init %C = class_init (), %a.var [template = constants.%C.val]
  146. // CHECK:STDOUT: %.loc32_3.2: init %C = converted %.loc32_15.1, %.loc32_15.2 [template = constants.%C.val]
  147. // CHECK:STDOUT: assign %a.var, %.loc32_3.2
  148. // CHECK:STDOUT: %C.ref.loc32: type = name_ref C, file.%C.decl [template = constants.%C]
  149. // CHECK:STDOUT: %a: ref %C = bind_name a, %a.var
  150. // CHECK:STDOUT: %a.ref.loc37: ref %C = name_ref a, %a
  151. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  152. // CHECK:STDOUT: %a.ref.loc42: ref %C = name_ref a, %a
  153. // CHECK:STDOUT: return
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT: