name_poisoning.carbon 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/none.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/name_poisoning.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/name_poisoning.carbon
  12. // --- using_poisoned_name_in_impl.carbon
  13. library "[[@TEST_NAME]]";
  14. interface I {};
  15. namespace N;
  16. // Use `package.I` and poison `N.I`.
  17. fn N.F1(x:! I);
  18. class N.C {
  19. extend impl as I {
  20. }
  21. }
  22. // --- fail_impl_function_poisoned.carbon
  23. library "[[@TEST_NAME]]";
  24. interface I {
  25. fn A(x: Self);
  26. fn B();
  27. }
  28. class B {
  29. impl as I {
  30. // CHECK:STDERR: fail_impl_function_poisoned.carbon:[[@LINE+3]]:13: error: name `B` used before it was declared [NameUseBeforeDecl]
  31. // CHECK:STDERR: fn A(x: B);
  32. // CHECK:STDERR: ^
  33. fn A(x: B);
  34. // TODO: Avoid ImplMissingFunction for functions that were declared after they were poisoned.
  35. // CHECK:STDERR: fail_impl_function_poisoned.carbon:[[@LINE+11]]:8: note: declared here [NameUseBeforeDeclNote]
  36. // CHECK:STDERR: fn B();
  37. // CHECK:STDERR: ^
  38. // CHECK:STDERR:
  39. // CHECK:STDERR: fail_impl_function_poisoned.carbon:[[@LINE-10]]:3: error: missing implementation of B in impl of interface I [ImplMissingFunction]
  40. // CHECK:STDERR: impl as I {
  41. // CHECK:STDERR: ^~~~~~~~~~~
  42. // CHECK:STDERR: fail_impl_function_poisoned.carbon:[[@LINE-17]]:3: note: associated function B declared here [AssociatedFunctionHere]
  43. // CHECK:STDERR: fn B();
  44. // CHECK:STDERR: ^~~~~~~
  45. // CHECK:STDERR:
  46. fn B();
  47. }
  48. }