impl_thunk_min_prelude.carbon 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. //
  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/impl_thunk_min_prelude.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/impl_thunk_min_prelude.carbon
  12. // --- convert_in_class.carbon
  13. library "[[@TEST_NAME]]";
  14. interface X(T:! type, U:! type) {
  15. fn F(t: T) -> U;
  16. }
  17. class ConvertsToA {}
  18. class ConvertsToB {}
  19. // Check that we don't try to define a thunk for `A.B.(as X).F` until we reach
  20. // the end of `A`. If we tried earlier, we wouldn't find a conversion from
  21. // `ConvertsToA` to `A` or from `ConvertsToB` to `B`.
  22. class A {
  23. class B {
  24. impl as X(ConvertsToA, B) {
  25. fn F(a: A) -> ConvertsToB;
  26. }
  27. impl ConvertsToB as Core.ImplicitAs(B) {
  28. fn Convert[self: Self]() -> B { return {}; }
  29. }
  30. }
  31. impl ConvertsToA as Core.ImplicitAs(A) {
  32. fn Convert[self: Self]() -> A { return {}; }
  33. }
  34. }