binding_self.carbon 641 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: 12
  9. package ExplorerTest api;
  10. interface SwizzleWith(T:! type) {
  11. fn Op[self: Self](x: T) -> i32;
  12. }
  13. impl i32 as SwizzleWith(i32) {
  14. fn Op[self: Self](x: Self) -> Self { return self * 10 + x; }
  15. }
  16. fn F[T:! SwizzleWith(.Self)](v: T, w: T) -> i32 {
  17. return v.Op(w);
  18. }
  19. fn Main() -> i32 {
  20. var one: i32 = 1;
  21. var two: i32 = 2;
  22. return F(one, two);
  23. }