param_lifetime.carbon 552 B

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