binding_self.carbon 587 B

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