impl_constraint.carbon 959 B

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