await_maintains_scope.carbon 562 B

1234567891011121314151617181920212223242526
  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. // Test access to block-scoped variables upon resuming a continuation.
  11. fn Main() -> i32 {
  12. var y: i32 = 0;
  13. __continuation k {
  14. var x: i32 = 0;
  15. x = x + 1;
  16. __await;
  17. x = x + 2;
  18. y = x;
  19. }
  20. __run k;
  21. __run k;
  22. return y;
  23. }