From 871e52006bf690b98363c0592fc1c84bf85f8efc Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 26 Mar 2021 16:51:03 -0400 Subject: [PATCH] quick bug fix --- ast/src/reducer/canonicalization.rs | 23 ++++++++++++++++++- .../canonicalization/compound_assignment.leo | 9 ++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index e9be54f691..fdf14af4e8 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -470,7 +470,28 @@ impl ReconstructingReducer for Canonicalizer { ) -> Result { match value { Expression::Value(value_expr) if assign.operation != AssignOperation::Assign => { - let left = Box::new(Expression::Identifier(assignee.identifier.clone())); + let mut left = Box::new(Expression::Identifier(assignee.identifier.clone())); + + for access in assignee.accesses.iter().rev() { + match self.canonicalize_assignee_access(&access) { + AssigneeAccess::ArrayIndex(index) => { + left = Box::new(Expression::ArrayAccess(ArrayAccessExpression { + array: left, + index: Box::new(index), + span: assign.span.clone(), + })); + } + AssigneeAccess::Tuple(positive_number, _) => { + left = Box::new(Expression::TupleAccess(TupleAccessExpression { + tuple: left, + index: positive_number, + span: assign.span.clone(), + })); + } + _ => {} + } + } + let right = Box::new(Expression::Value(value_expr)); let op = match assign.operation { diff --git a/compiler/tests/canonicalization/compound_assignment.leo b/compiler/tests/canonicalization/compound_assignment.leo index 95c810a7d5..6f4b9834ae 100644 --- a/compiler/tests/canonicalization/compound_assignment.leo +++ b/compiler/tests/canonicalization/compound_assignment.leo @@ -1,4 +1,13 @@ function main() { let x = 10u32; x += 20; + console.assert(x == 30u32); + + let y = [1u8, 2u8]; + y[0] += 3u8; + console.assert(y[0] == 4u8); + + let z = (1u8, 2u8); + z.1 += 3u8; + console.assert(z.1 == 5u8); } \ No newline at end of file