sub.carbon 670 B

1234567891011121314151617181920212223242526272829
  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: 4
  9. // CHECK:STDOUT: 3
  10. // CHECK:STDOUT: 2
  11. // CHECK:STDOUT: result: 0
  12. package ExplorerTest api;
  13. class A { var n: i32; }
  14. external impl A as SubWith(i32) where .Result = A {
  15. fn Op[self: Self](rhs: i32) -> A { return {.n = self.n - rhs}; }
  16. }
  17. fn Main() -> i32 {
  18. var a: A = {.n = 5};
  19. a = a - 1;
  20. Print("{0}", a.n);
  21. a -= 1;
  22. Print("{0}", a.n);
  23. Print("{0}", (a - 1).n);
  24. return 0;
  25. }