core: Fix crashes on invalid subscripting & iterating over non-iterables. #440

Merged
sb10q merged 1 commits from fix-panic-432 into master 2024-08-17 17:37:21 +08:00
1 changed files with 11 additions and 1 deletions
Showing only changes of commit 56fa2b6803 - Show all commits

View File

@ -248,7 +248,17 @@ impl<'a> Fold<()> for Inferencer<'a> {
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => { TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
todo!() todo!()
} }
_ => unreachable!(), _ => {
// User is attempting to use a for loop to iterate
// over a value of an unsupported type.
let iter_ty = iter.custom.unwrap();
let iter_ty_str = self.unifier.stringify(iter_ty);
return report_error(
format!("'{iter_ty_str}' object is not iterable").as_str(),
iter.location,
);
}
}; };
self.unify(list_like_ty, iter.custom.unwrap(), &iter.location)?; self.unify(list_like_ty, iter.custom.unwrap(), &iter.location)?;
} }