leo/compiler/tests/function/value_unchanged.leo

19 lines
542 B
Plaintext
Raw Normal View History

2020-08-01 06:59:50 +03:00
// Functions input in leo are pass-by-value.
//
// Program execution:
// line 15: variable `a` is defined with value `1`.
// line 16: value `1` is copied and passed into function `bad_mutate()`.
// line 10: variable `x` is defined with value `1`.
// line 11: variable `x` is set to value `0`.
// line 18: program returns the value of `a`.
2021-03-19 18:30:24 +03:00
function bad_mutate(x: u32) {
x = 0; // <- does not change `a`
}
2020-07-30 22:10:33 +03:00
function main() {
const a = 1u32;
bad_mutate(a);
2020-08-17 05:14:26 +03:00
console.assert(a == 1u32); // <- value `a` is still `1u32`
}