qualified_param_member.carbon 616 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. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: result: 3
  9. package Foo api;
  10. interface A {
  11. fn F[self: Self](o: Self) -> Self;
  12. }
  13. class X {
  14. impl as A {
  15. fn F[self: Self](o: Self) -> Self { return {.n = self.n + o.n}; }
  16. }
  17. var n: i32;
  18. }
  19. fn F[T:! A](v: T, w: T) -> T {
  20. return v.(T.F)(w);
  21. }
  22. fn Main() -> i32 {
  23. var v: X = {.n = 1};
  24. var w: X = {.n = 2};
  25. return F(v, w).n;
  26. }