fail_method.carbon 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/convert.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_method.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_method.carbon
  12. class Class {
  13. fn NoSelf();
  14. fn WithSelf[self: Class]();
  15. }
  16. alias A = Class.WithSelf;
  17. fn F(c: Class) {
  18. c.NoSelf();
  19. c.WithSelf();
  20. Class.NoSelf();
  21. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: error: missing object argument in method call [MissingObjectInMethodCall]
  22. // CHECK:STDERR: Class.WithSelf();
  23. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  24. // CHECK:STDERR: fail_method.carbon:[[@LINE-13]]:3: note: calling function declared here [InCallToFunction]
  25. // CHECK:STDERR: fn WithSelf[self: Class]();
  26. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. // CHECK:STDERR:
  28. Class.WithSelf();
  29. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: error: 1 argument passed to function expecting 0 arguments [CallArgCountMismatch]
  30. // CHECK:STDERR: Class.WithSelf(c);
  31. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  32. // CHECK:STDERR: fail_method.carbon:[[@LINE-21]]:3: note: calling function declared here [InCallToEntity]
  33. // CHECK:STDERR: fn WithSelf[self: Class]();
  34. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. // CHECK:STDERR:
  36. Class.WithSelf(c);
  37. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: error: missing object argument in method call [MissingObjectInMethodCall]
  38. // CHECK:STDERR: A();
  39. // CHECK:STDERR: ^~~
  40. // CHECK:STDERR: fail_method.carbon:[[@LINE-30]]:3: note: calling function declared here [InCallToFunction]
  41. // CHECK:STDERR: fn WithSelf[self: Class]();
  42. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. // CHECK:STDERR:
  44. A();
  45. }