impl_thunk.carbon 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/convert.carbon
  6. // EXTRA-ARGS: --no-dump-sem-ir --custom-core
  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/impl_thunk.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/impl_thunk.carbon
  13. // --- convert_in_class.carbon
  14. library "[[@TEST_NAME]]";
  15. interface X(T:! type, U:! type) {
  16. fn F(t: T) -> U;
  17. }
  18. class ConvertsToA {}
  19. class ConvertsToB {}
  20. // Check that we don't try to define a thunk for `A.B.(as X).F` until we reach
  21. // the end of `A`. If we tried earlier, we wouldn't find a conversion from
  22. // `ConvertsToA` to `A` or from `ConvertsToB` to `B`.
  23. class A {
  24. class B {
  25. impl as X(ConvertsToA, B) {
  26. fn F(a: A) -> ConvertsToB;
  27. }
  28. impl ConvertsToB as Core.ImplicitAs(B) {
  29. fn Convert[self: Self]() -> B { return {}; }
  30. }
  31. }
  32. impl ConvertsToA as Core.ImplicitAs(A) {
  33. fn Convert[self: Self]() -> A { return {}; }
  34. }
  35. }