rewrite_interface_params.carbon 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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: 0
  9. package ExplorerTest api;
  10. interface HasTypes {
  11. let A:! type;
  12. let B:! type;
  13. let C:! type;
  14. let D:! type;
  15. let E:! type;
  16. let F:! type;
  17. }
  18. interface HasParams(A:! type, B:! type, C:! type, D:! type) {
  19. let V:! HasTypes;
  20. }
  21. // Here we discover that there is a rewrite for `HasParams(...).V` only after
  22. // substitution converts each one to `HasParam(X, X, X, X).V`.
  23. fn F[X:! (HasTypes & HasParams(.Self, .Self, .Self, .Self)) where
  24. .Self impls HasParams(.A, .A, .A, .A) and
  25. .Self impls HasParams(.B, .B, .B, .B) and
  26. .Self impls HasParams(.C, .C, .C, .C) and
  27. .Self impls HasParams(.D, .D, .D, .D) and
  28. .Self impls HasParams(.E, .E, .E, .E) and
  29. .F = .Self.(HasParams(.E, .E, .E, .E).V).A and
  30. .E = .Self.(HasParams(.D, .D, .D, .D).V).A and
  31. .D = .Self.(HasParams(.C, .C, .C, .C).V).A and
  32. .C = .Self.(HasParams(.B, .B, .B, .B).V).A and
  33. .B = .Self.(HasParams(.A, .A, .A, .A).V).A and
  34. .A = .Self and .V = .Self](x: X) -> X.F { return x; }
  35. impl i32 as HasTypes
  36. where .A = .B and .B = .C and .C = .D and .D = .E and .E = .F and .F = i32 {}
  37. impl i32 as HasParams(i32, i32, i32, i32) where .V = i32 {}
  38. fn Main() -> i32 {
  39. return F(0);
  40. }