Skip to content

Commit

Permalink
tycheck: better error message for immutable assigns
Browse files Browse the repository at this point in the history
fixes #31
  • Loading branch information
Philipp15b committed Jun 22, 2024
1 parent 5d735e3 commit ff1961e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/front/tycheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ impl<'tcx> Tycheck<'tcx> {
for (lhs, rhs_ty) in lhses.iter().zip(rhs_tys) {
let lhs_decl_ref = self.get_var_decl(span, *lhs)?;
let lhs_decl = lhs_decl_ref.borrow();
if !lhs_decl.kind.is_mutable() {
return Err(TycheckError::CannotAssign {
span,
lhs_decl: lhs_decl_ref.clone(),
});
}
if &lhs_decl.ty != rhs_ty {
return Err(TycheckError::TypeMismatch {
span,
lhs: lhs_decl.ty.clone().into(),
rhs: rhs_ty.clone().into(),
});
}
if !lhs_decl.kind.is_mutable() {
return Err(TycheckError::CannotAssign {
span,
lhs_decl: lhs_decl_ref.clone(),
});
}
}
Ok(())
}
Expand Down Expand Up @@ -521,13 +521,13 @@ impl<'tcx> VisitorMut for Tycheck<'tcx> {
if let Some(lhs) = lhs_singleton {
let lhs_decl_ref = self.get_var_decl(s.span, *lhs)?;
let lhs_decl = lhs_decl_ref.borrow();
self.try_cast(s.span, &lhs_decl.ty, rhs)?;
if !lhs_decl.kind.is_mutable() {
return Err(TycheckError::CannotAssign {
span: s.span,
lhs_decl: lhs_decl_ref.clone(),
});
}
self.try_cast(s.span, &lhs_decl.ty, rhs)?;
} else {
return Err(TycheckError::UnpackMismatch {
span: s.span,
Expand Down

0 comments on commit ff1961e

Please sign in to comment.