impls_constraint.carbon 715 B

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