Repository: MystenLabs/sui
File: external-crates/move/crates/move-compiler/src/hlir/translate.rs (Rust)

Code before:
    }
}

fn make_assignments(
    context: &mut Context,
    result: &mut Block,
    loc: Loc,
    case: H::AssignCase,
    sp!(_, assigns): T::LValueList,
    rvalue: H::Exp,
) {
    use H::{Command_ as C, Statement_ as S};
    let mut lvalues = vec![];
    let mut after = Block::new();
    for (idx, a) in assigns.into_iter().enumerate() {
        let error_ty;
        let a_ty = match rvalue.ty.value.type_at_index(idx) {
            Some(ty) => ty,
            None => {
                // we can only get here if the rvalue was malformed and somewhere has an unresolved
                // error
                debug_assert!(context.env.has_errors());
                error_ty = error_single_type(a.loc);
                &error_ty
            }
        };
        let (ls, mut af) = assign(context, case, a, a_ty);

        lvalues.push(ls);
        after.append(&mut af);
    }
    result.push_back(sp(
        loc,
        S::Command(sp(loc, C::Assign(case, lvalues, rvalue))),
    ));
    result.append(&mut after);
}

fn assign(
    context: &mut Context,
    case: H::AssignCase,
    sp!(loc, ta_): T::LValue,
    rvalue_ty: &H::SingleType,
) -> (H::LValue, Block) {
    use H::{LValue_ as L, UnannotatedExp_ as E};
    use T::LValue_ as A;
    let mut after = Block::new();
    let l_ = match ta_ {
        A::Ignore => L::Ignore,
        A::Var {
            var: v,

Review comment (bug):
😢 I see _why_ but damn this is awful. Is this any better?
```
  let error_ty = error_single_type(a.loc);
  let a_ty = rvalue.ty.value.type_at_index(idx).unwrap_or_else(|| {
      debug_assert!(context.env.has_errors());
      &error_ty
  });
```

Code after:
    }
}

fn make_assignments(
    context: &mut Context,
    result: &mut Block,
    loc: Loc,
    case: H::AssignCase,
    sp!(_, assigns): T::LValueList,
    rvalue: H::Exp,
) {
    use H::{Command_ as C, Statement_ as S};
    let mut lvalues = vec![];
    let mut after = Block::new();
    for (idx, a) in assigns.into_iter().enumerate() {
        let error_ty = error_single_type(a.loc);
        let a_ty = rvalue.ty.value.type_at_index(idx).unwrap_or_else(|| {
            // we can only get here if the rvalue was malformed and somewhere has an unresolved
            // erro
            ice_assert!(
                context,
                context.env.has_errors(),
                a.loc,
                "Unable to find a type for assignment lvalue from the rvalue"
            );
            &error_ty
        });
        let (ls, mut af) = assign(context, case, a, a_ty);

        lvalues.push(ls);
        after.append(&mut af);
    }
    result.push_back(sp(
        loc,
        S::Command(sp(loc, C::Assign(case, lvalues, rvalue))),
    ));
    result.append(&mut after);
}

fn assign(
    context: &mut Context,
    case: H::AssignCase,
    sp!(loc, ta_): T::LValue,
    rvalue_ty: &H::SingleType,
) -> (H::LValue, Block) {
    use H::{LValue_ as L, UnannotatedExp_ as E};
    use T::LValue_ as A;
    let mut after = Block::new();
    let l_ = match ta_ {
        A::Ignore => L::Ignore,
        A::Var {