fail_method_modifiers.carbon 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/method/fail_method_modifiers.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/method/fail_method_modifiers.carbon
  12. class FinalClass {
  13. // CHECK:STDERR: fail_method_modifiers.carbon:[[@LINE+7]]:3: error: `abstract` not allowed; requires `abstract` class scope [ModifierAbstractNotAllowed]
  14. // CHECK:STDERR: abstract fn Abstract[self: Self]();
  15. // CHECK:STDERR: ^~~~~~~~
  16. // CHECK:STDERR: fail_method_modifiers.carbon:[[@LINE-5]]:1: note: containing definition here [ModifierNotInContext]
  17. // CHECK:STDERR: class FinalClass {
  18. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  19. // CHECK:STDERR:
  20. abstract fn Abstract[self: Self]();
  21. // CHECK:STDERR: fail_method_modifiers.carbon:[[@LINE+7]]:3: error: `virtual` not allowed; requires `abstract` or `base` class scope [ModifierVirtualNotAllowed]
  22. // CHECK:STDERR: virtual fn Virtual[self: Self]();
  23. // CHECK:STDERR: ^~~~~~~
  24. // CHECK:STDERR: fail_method_modifiers.carbon:[[@LINE-14]]:1: note: containing definition here [ModifierNotInContext]
  25. // CHECK:STDERR: class FinalClass {
  26. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  27. // CHECK:STDERR:
  28. virtual fn Virtual[self: Self]();
  29. }
  30. abstract class AbstractClass {
  31. // CHECK:STDERR: fail_method_modifiers.carbon:[[@LINE+4]]:3: error: `default` not allowed; requires interface scope [ModifierRequiresInterface]
  32. // CHECK:STDERR: default fn Default[self: Self]();
  33. // CHECK:STDERR: ^~~~~~~
  34. // CHECK:STDERR:
  35. default fn Default[self: Self]();
  36. // CHECK:STDERR: fail_method_modifiers.carbon:[[@LINE+4]]:3: error: `final` not allowed; requires interface scope [ModifierRequiresInterface]
  37. // CHECK:STDERR: final fn Final[self: Self]();
  38. // CHECK:STDERR: ^~~~~
  39. // CHECK:STDERR:
  40. final fn Final[self: Self]();
  41. }
  42. base class BaseClass {
  43. // CHECK:STDERR: fail_method_modifiers.carbon:[[@LINE+7]]:3: error: `abstract` not allowed; requires `abstract` class scope [ModifierAbstractNotAllowed]
  44. // CHECK:STDERR: abstract fn Abstract[self: Self]();
  45. // CHECK:STDERR: ^~~~~~~~
  46. // CHECK:STDERR: fail_method_modifiers.carbon:[[@LINE-5]]:1: note: containing definition here [ModifierNotInContext]
  47. // CHECK:STDERR: base class BaseClass {
  48. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
  49. // CHECK:STDERR:
  50. abstract fn Abstract[self: Self]();
  51. }