extend_final.carbon 1.7 KB

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