assign_builtin.carbon 625 B

123456789101112131415161718192021222324252627
  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: Before: 1
  9. // CHECK:STDOUT: Interface: 2
  10. // CHECK:STDOUT: Op: 3
  11. // CHECK:STDOUT: result: 0
  12. package ExplorerTest api;
  13. class C {
  14. var n: i32;
  15. }
  16. fn Main() -> i32 {
  17. var c: C = {.n = 1};
  18. Print("Before: {0}", c.n);
  19. c.(AssignWith({.n: i32}).Op)({.n = 2});
  20. Print("Interface: {0}", c.n);
  21. c = {.n = 3};
  22. Print("Op: {0}", c.n);
  23. return 0;
  24. }