extend_final.carbon 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/impl/extend_final.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/extend_final.carbon
  12. // --- extend_final_impl.carbon
  13. library "[[@TEST_NAME]]";
  14. interface Z {
  15. let X:! type;
  16. }
  17. class C {
  18. extend final impl as Z where .X = () {}
  19. }
  20. fn F() {
  21. let unused b: C.X = ();
  22. }
  23. // --- fail_final_extend_impl.carbon
  24. library "[[@TEST_NAME]]";
  25. interface Z {}
  26. class C {
  27. // CHECK:STDERR: fail_final_extend_impl.carbon:[[@LINE+7]]:9: error: `extend` must appear before `final` [ModifierMustAppearBefore]
  28. // CHECK:STDERR: final extend impl as Z {}
  29. // CHECK:STDERR: ^~~~~~
  30. // CHECK:STDERR: fail_final_extend_impl.carbon:[[@LINE+4]]:3: note: `final` previously appeared here [ModifierPrevious]
  31. // CHECK:STDERR: final extend impl as Z {}
  32. // CHECK:STDERR: ^~~~~
  33. // CHECK:STDERR:
  34. final extend impl as Z {}
  35. }
  36. // --- fail_final_extend_impl_outside_class.carbon
  37. library "[[@TEST_NAME]]";
  38. interface Z {}
  39. class C {}
  40. // CHECK:STDERR: fail_final_extend_impl_outside_class.carbon:[[@LINE+4]]:1: error: `extend impl` can only be used in an interface or class [ExtendImplOutsideClass]
  41. // CHECK:STDERR: extend final impl C as Z {}
  42. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~
  43. // CHECK:STDERR:
  44. extend final impl C as Z {}