impl_constraint.carbon 766 B

123456789101112131415161718192021222324252627282930313233343536
  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: 1234
  9. package ExplorerTest api;
  10. interface A {
  11. fn F() -> i32;
  12. }
  13. interface B {
  14. fn F() -> i32;
  15. fn G() -> i32;
  16. }
  17. interface C(T:! Type) {
  18. fn H() -> T;
  19. }
  20. external impl i32 as A {
  21. fn F() -> i32 { return 1; }
  22. }
  23. external impl i32 as B & C(i32) where .Self is A {
  24. fn F() -> i32 { return 2; }
  25. fn G() -> i32 { return 3; }
  26. fn H() -> i32 { return 4; }
  27. }
  28. fn Main() -> i32 {
  29. let n: i32 = 0;
  30. return n.(A.F)() * 1000 + n.(B.F)() * 100 + n.(B.G)() * 10 + n.(C(i32).H)();
  31. }