binding_self.carbon 590 B

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