convert_lhs_interface.carbon 661 B

123456789101112131415161718192021222324252627282930313233
  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. // NOAUTOUPDATE
  6. package Foo api;
  7. interface HasF {
  8. fn F[self: Self](o: Self) -> Self;
  9. }
  10. class X {
  11. extend impl as HasF {
  12. fn F[self: Self](o: Self) -> Self { return {.n = self.n + o.n}; }
  13. }
  14. var n: i32;
  15. }
  16. class Y {
  17. var m: i32;
  18. extend impl as ImplicitAs(X) {
  19. fn Convert[self: Self]() -> X { return {.n = self.m}; }
  20. }
  21. }
  22. fn Main() -> i32 {
  23. var x: X = {.n = 1};
  24. var y: Y = {.m = 2};
  25. return y.(X.(HasF.F))(x).n;
  26. }
  27. // CHECK:STDOUT: result: 3