use_impl_from_definition.carbon 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/lookup/use_impl_from_definition.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/lookup/use_impl_from_definition.carbon
  12. // --- construct_facet_value_inside_definition.carbon
  13. library "[[@TEST_NAME]]";
  14. interface I {
  15. let U:! type;
  16. fn F() -> U;
  17. }
  18. class C { adapt {}; }
  19. impl forall [T:! type] T as I where .U = C {
  20. // `T as I` does an impl lookup to form a FacetValue, which must find the impl
  21. // being defined and use that. The witness must be a final witness in order to
  22. // know that `U` is `C`.
  23. fn F() -> (T as I).U { return {} as C; }
  24. }
  25. // --- construct_facet_value_from_self_inside_definition.carbon
  26. library "[[@TEST_NAME]]";
  27. interface I {
  28. let U:! type;
  29. fn F() -> U;
  30. }
  31. class C { adapt {}; }
  32. impl forall [T:! type] T as I where .U = C {
  33. // `Self as I` is a symbolic facet value specified in the interface-with-self
  34. // specific, and then monomorphized with the self type of the impl.
  35. fn F() -> (Self as I).U { return {} as C; }
  36. }