quick bug fix

This commit is contained in:
gluax 2021-03-26 16:51:03 -04:00
parent 9bc53eb594
commit 871e52006b
2 changed files with 31 additions and 1 deletions

View File

@ -470,7 +470,28 @@ impl ReconstructingReducer for Canonicalizer {
) -> Result<AssignStatement, CanonicalizeError> {
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 {

View File

@ -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);
}