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