add.carbon 607 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. package ExplorerTest api;
  7. class A { var n: i32; }
  8. impl A as Add {
  9. fn Op[self: Self](rhs: A) -> A { return {.n = self.n + rhs.n}; }
  10. }
  11. fn Main() -> i32 {
  12. var a: A = {.n = 5};
  13. var b: A = {.n = 7};
  14. a = a + b;
  15. Print("{0}", a.n);
  16. a += b;
  17. Print("{0}", a.n);
  18. Print("{0}", (a + b).n);
  19. return 0;
  20. }
  21. // CHECK:STDOUT: 12
  22. // CHECK:STDOUT: 19
  23. // CHECK:STDOUT: 26
  24. // CHECK:STDOUT: result: 0