convert_lhs_class.carbon 800 B

123456789101112131415161718192021222324252627282930
  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. // RUN: %{explorer} %s 2>&1 | \
  6. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
  7. // RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
  8. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
  9. // AUTOUPDATE: %{explorer} %s
  10. // CHECK: result: 3
  11. package Foo api;
  12. class X {
  13. fn F[me: Self](o: Self) -> Self { return {.n = me.n + o.n}; }
  14. var n: i32;
  15. }
  16. class Y {
  17. var m: i32;
  18. impl as ImplicitAs(X) {
  19. fn Convert[me: Self]() -> X { return {.n = me.m}; }
  20. }
  21. }
  22. fn Main() -> i32 {
  23. var y1: Y = {.m = 1};
  24. var y2: Y = {.m = 2};
  25. return y1.(X.F)(y2).n;
  26. }