simple_constraint.carbon 607 B

12345678910111213141516171819202122232425262728
  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: 3
  9. package ExplorerTest api;
  10. interface Frob {
  11. let Result:! type;
  12. fn F[self: Self]() -> Result;
  13. }
  14. fn Use[T:! Frob where .Result = .Self](x: T) -> T {
  15. var v: T = x.F();
  16. return v;
  17. }
  18. impl i32 as Frob where .Result = i32 {
  19. fn F[self: Self]() -> i32 { return self + 1; }
  20. }
  21. fn Main() -> i32 {
  22. return Use(2);
  23. }