fail_local_decl.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/destroy.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/function/definition/fail_local_decl.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/definition/fail_local_decl.carbon
  12. // --- fail_virtual.carbon
  13. library "[[@TEST_NAME]]";
  14. fn F() {
  15. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `default` not allowed; requires interface scope [ModifierRequiresInterface]
  16. // CHECK:STDERR: default fn F();
  17. // CHECK:STDERR: ^~~~~~~
  18. // CHECK:STDERR:
  19. default fn F();
  20. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `override` not allowed; requires class scope [ModifierRequiresClass]
  21. // CHECK:STDERR: override fn G();
  22. // CHECK:STDERR: ^~~~~~~~
  23. // CHECK:STDERR:
  24. override fn G();
  25. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `virtual` not allowed; requires class scope [ModifierRequiresClass]
  26. // CHECK:STDERR: virtual fn H();
  27. // CHECK:STDERR: ^~~~~~~
  28. // CHECK:STDERR:
  29. virtual fn H();
  30. }
  31. // --- fail_access.carbon
  32. library "[[@TEST_NAME]]";
  33. fn F() {
  34. // CHECK:STDERR: fail_access.carbon:[[@LINE+4]]:3: error: `private` not allowed; requires class or file scope [ModifierPrivateNotAllowed]
  35. // CHECK:STDERR: private var unused v: {} = {};
  36. // CHECK:STDERR: ^~~~~~~
  37. // CHECK:STDERR:
  38. private var unused v: {} = {};
  39. // CHECK:STDERR: fail_access.carbon:[[@LINE+4]]:3: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
  40. // CHECK:STDERR: protected var unused w: {} = {};
  41. // CHECK:STDERR: ^~~~~~~~~
  42. // CHECK:STDERR:
  43. protected var unused w: {} = {};
  44. }