add_with.carbon 536 B

12345678910111213141516171819202122
  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: result: 6
  9. package ExplorerTest api;
  10. class A { var n: i32; }
  11. external impl A as AddWith(i32) where .Result = A {
  12. fn Op[self: Self](rhs: i32) -> A { return {.n = self.n + rhs}; }
  13. }
  14. fn Main() -> i32 {
  15. var a: A = {.n = 5};
  16. a = a + 1;
  17. return a.n;
  18. }