shallow_copy.carbon 608 B

12345678910111213141516171819202122232425262728293031
  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: 3
  9. package ExplorerTest api;
  10. // Assignment for continuations is shallow, so `k2` refers to the same
  11. // continuation as `k1`.
  12. var x: i32 = 0;
  13. fn Foo() {
  14. x = x + 1;
  15. __await;
  16. x = x + 2;
  17. }
  18. fn Main() -> i32 {
  19. __continuation k1 {
  20. Foo();
  21. }
  22. var k2: __Continuation = k1;
  23. __run k1;
  24. __run k2;
  25. return x;
  26. }