From 59f86c4b34ffc684c21430f5e25aeb501f7818b9 Mon Sep 17 00:00:00 2001 From: gluax Date: Thu, 15 Apr 2021 14:34:22 -0400 Subject: [PATCH] fix call for immutable context, add it to test --- asg/src/expression/call.rs | 2 +- .../circuits/mutable_call_immutable_context.leo | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/asg/src/expression/call.rs b/asg/src/expression/call.rs index ada5458e5c..d0ae36f32e 100644 --- a/asg/src/expression/call.rs +++ b/asg/src/expression/call.rs @@ -71,7 +71,7 @@ impl<'a> ExpressionNode<'a> for CallExpression<'a> { } fn is_mut_ref(&self) -> bool { - false + true } fn const_value(&self) -> Option { diff --git a/compiler/tests/circuits/mutable_call_immutable_context.leo b/compiler/tests/circuits/mutable_call_immutable_context.leo index d68e1866c5..d235d11cb7 100644 --- a/compiler/tests/circuits/mutable_call_immutable_context.leo +++ b/compiler/tests/circuits/mutable_call_immutable_context.leo @@ -3,10 +3,23 @@ circuit TestMe { function test_me(mut self) -> u8 { self.x += 1; - return self.x + return self.x; } + + function new() -> Self { + return Self { x: 1u8 }; + } +} + +function my_fn() -> TestMe { + return TestMe { x: 0u8 }; } function main () { const t = TestMe {x: 6u8}.test_me(); + console.assert(t == 7u8); + const u = my_fn().test_me(); + console.assert(u == 1u8); + const v = TestMe::new().test_me(); + console.assert(v == 2u8); } \ No newline at end of file