combined_interfaces.carbon 741 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. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. interface A { fn F() -> i32; fn G() -> i32; }
  8. interface B { fn H() -> i32; }
  9. fn Get1[T:! A & B](n: T) -> i32 { return n.F() + n.H(); }
  10. fn Get2[T:! B & A](n: T) -> i32 { return n.G(); }
  11. fn Get3[T:! B & A & A & B & A](n: T) -> i32 { return n.G() + n.H(); }
  12. impl i32 as A {
  13. fn F() -> i32 { return 1; }
  14. fn G() -> i32 { return 2; }
  15. }
  16. impl i32 as B {
  17. fn H() -> i32 { return 4; }
  18. }
  19. fn Main() -> i32 {
  20. var z: i32 = 0;
  21. return Get1(z) * 100 + Get2(z) * 10 + Get3(z);
  22. }
  23. // CHECK:STDOUT: result: 526