Compare commits
2 Commits
9808923258
...
56fa2b6803
Author | SHA1 | Date | |
---|---|---|---|
56fa2b6803 | |||
d06c13f936 |
@ -248,7 +248,17 @@ impl<'a> Fold<()> for Inferencer<'a> {
|
||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||
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)?;
|
||||
}
|
||||
@ -1856,6 +1866,18 @@ impl<'a> Inferencer<'a> {
|
||||
slice: &ast::Expr<Option<Type>>,
|
||||
ctx: ExprContext,
|
||||
) -> InferenceResult {
|
||||
let report_unscriptable_error = |unifier: &mut Unifier| {
|
||||
// User is attempting to index into a value of an unsupported type.
|
||||
|
||||
let value_ty = value.custom.unwrap();
|
||||
let value_ty_str = unifier.stringify(value_ty);
|
||||
|
||||
return report_error(
|
||||
format!("'{value_ty_str}' object is not subscriptable").as_str(),
|
||||
slice.location, // using the slice's location (rather than value's) because it is more clear
|
||||
);
|
||||
};
|
||||
|
||||
let ty = self.unifier.get_dummy_var().ty;
|
||||
match &slice.node {
|
||||
ExprKind::Slice { lower, upper, step } => {
|
||||
@ -1871,7 +1893,9 @@ impl<'a> Inferencer<'a> {
|
||||
make_ndarray_ty(self.unifier, self.primitives, Some(ty), Some(ndims))
|
||||
}
|
||||
|
||||
_ => unreachable!(),
|
||||
_ => {
|
||||
return report_unscriptable_error(self.unifier);
|
||||
}
|
||||
};
|
||||
self.constrain(value.custom.unwrap(), list_like_ty, &value.location)?;
|
||||
Ok(list_like_ty)
|
||||
@ -1961,7 +1985,7 @@ impl<'a> Inferencer<'a> {
|
||||
self.constrain(slice.custom.unwrap(), valid_index_ty, &slice.location)?;
|
||||
self.infer_subscript_ndarray(value, slice, ty, ndims)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
_ => report_unscriptable_error(self.unifier),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user