Variable Assignment Fix #287

Merged
sb10q merged 1 commits from 285-fix-var-assign into master 2022-05-14 16:00:37 +08:00
1 changed files with 12 additions and 9 deletions

View File

@ -42,15 +42,18 @@ pub fn gen_store_target<'ctx, 'a, G: CodeGenerator>(
// very similar to gen_expr, but we don't do an extra load at the end
// and we flatten nested tuples
Ok(match &pattern.node {
ExprKind::Name { id, .. } => {
ctx.var_assignment.get(id).map(|v| Ok(v.0) as Result<_, String>).unwrap_or_else(
|| {
ExprKind::Name { id, .. } => match ctx.var_assignment.get(id) {
None => {
let ptr_ty = ctx.get_llvm_type(generator, pattern.custom.unwrap());
let ptr = generator.gen_var_alloc(ctx, ptr_ty)?;
ctx.var_assignment.insert(*id, (ptr, None, 0));
Ok(ptr)
},
)?
ptr
}
Some(v) => {
let (ptr, counter) = (v.0, v.2);
ctx.var_assignment.insert(*id, (ptr, None, counter));
ptr
}
}
ExprKind::Attribute { value, attr, .. } => {
let index = ctx.get_attr_index(value.custom.unwrap(), *attr);