convert_lhs_class.carbon 569 B

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