impl_constraint.carbon 740 B

12345678910111213141516171819202122232425262728293031323334353637
  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: 12
  9. package ExplorerTest api;
  10. interface Runnable {
  11. fn Run[self: Self]() -> i32;
  12. }
  13. interface Walkable {
  14. fn Walk[self: Self]() -> i32;
  15. }
  16. constraint Traversible {
  17. extends Runnable;
  18. extends Walkable;
  19. }
  20. external impl i32 as Traversible {
  21. fn Run[self: i32]() -> i32 {
  22. return 10 * self;
  23. }
  24. fn Walk[self: i32]() -> i32 {
  25. return self + 1;
  26. }
  27. }
  28. fn Main() -> i32 {
  29. var n: i32 = 1;
  30. return n.(Runnable.Run)() + n.(Walkable.Walk)();
  31. }