param_lifetime.carbon 606 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: 0
  9. package ExplorerTest api;
  10. // This tests the call-by-value aspect of parameter passing.
  11. // This makes sure that when the value in `x` dies,
  12. // it does not cause the value in `a` to also die.
  13. fn f(x: i32) -> i32 {
  14. return 0;
  15. }
  16. fn Main() -> i32 {
  17. var a: i32 = 0;
  18. var b: i32 = 1;
  19. f(a);
  20. b = a;
  21. return b;
  22. }