leo/tests/compiler/circuits/mut_self_variable_branch.leo

38 lines
553 B
Plaintext
Raw Normal View History

2021-05-05 11:37:51 +03:00
/*
namespace: Compile
expectation: Pass
*/
2020-12-17 00:02:31 +03:00
circuit Foo {
a: u8,
function set_a(mut self, condition: bool, new: u8) {
if condition {
self.a = new;
console.assert(self.a == new);
}
}
}
function main() {
let f = Foo { a: 0u8 };
2020-12-17 00:02:31 +03:00
console.assert(f.a == 0u8);
f.set_a(false, 1u8);
console.assert(f.a == 0u8);
f.set_a(true, 1u8);
console.assert(f.a == 1u8);
f.set_a(false, 2u8);
console.assert(f.a == 1u8);
f.set_a(true, 2u8);
console.assert(f.a == 2u8);
2021-05-05 11:37:51 +03:00
}