combined_interfaces.carbon 985 B

1234567891011121314151617181920212223242526272829303132
  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. // RUN: %{explorer} %s 2>&1 | \
  6. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
  7. // RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
  8. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
  9. // AUTOUPDATE: %{explorer} %s
  10. // CHECK: result: 526
  11. package ExplorerTest api;
  12. interface A { fn F() -> i32; fn G() -> i32; }
  13. interface B { fn H() -> i32; }
  14. fn Get1[T:! A & B](n: T) -> i32 { return n.F() + n.H(); }
  15. fn Get2[T:! B & A](n: T) -> i32 { return n.G(); }
  16. fn Get3[T:! B & A & A & B & A](n: T) -> i32 { return n.G() + n.H(); }
  17. impl i32 as A {
  18. fn F() -> i32 { return 1; }
  19. fn G() -> i32 { return 2; }
  20. }
  21. impl i32 as B {
  22. fn H() -> i32 { return 4; }
  23. }
  24. fn Main() -> i32 {
  25. var z: i32 = 0;
  26. return Get1(z) * 100 + Get2(z) * 10 + Get3(z);
  27. }