2e1aea3071937c4307dd48ebb2b1df3bc9e8716f 624 B

1234567891011121314151617181920212223242526272829
  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. // CHECK:STDOUT: result: 12
  7. package Foo;
  8. interface A {
  9. fn F[self: Self]() -> i32;
  10. }
  11. interface B {
  12. fn G(o: Self) -> i32;
  13. }
  14. alias C = A & B;
  15. class X {
  16. extend impl as A {
  17. fn F[self: Self]() -> i32 { return 10 * self.n; }
  18. }
  19. extend impl as B {
  20. fn G(o: Self) -> i32 { return o.n; }
  21. }
  22. var n: i32;
  23. }
  24. fn Main() -> i32 {
  25. var v: X = {.n = 1};
  26. var w: X = {.n = 2};
  27. return v.(C.F)() + X.(C.G)(w);
  28. }