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