combined_interfaces.carbon 738 B

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