core/typecheck: Explicitly give errors on "advanced" (subset) indexing
This commit is contained in:
parent
c74b7992f6
commit
164edd266e
@ -1181,21 +1181,38 @@ impl<'a> Inferencer<'a> {
|
|||||||
slice.location,
|
slice.location,
|
||||||
),
|
),
|
||||||
TypeEnum::TNDArray { ty: elem_ty, num_dims } => {
|
TypeEnum::TNDArray { ty: elem_ty, num_dims } => {
|
||||||
let num_idxs = if let TypeEnum::TTuple { ty: idx_tys } =
|
let num_idxs = match &*self.unifier.get_ty(slice.custom.unwrap()) {
|
||||||
&*self.unifier.get_ty(slice.custom.unwrap())
|
TypeEnum::TTuple { ty: idx_tys } => {
|
||||||
{
|
for idx_ty in idx_tys.iter() {
|
||||||
for idx_ty in idx_tys.iter() {
|
// xxx: NumPy supports a tuple of tuples for "advanced indexing"
|
||||||
self.constrain(*idx_ty, self.primitives.int32, &slice.location)?;
|
// of multidimensional arrays (sequence index -> subset). We
|
||||||
|
// don't support this, but could give a better error message.
|
||||||
|
self.constrain(
|
||||||
|
*idx_ty,
|
||||||
|
self.primitives.int32,
|
||||||
|
&slice.location,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
idx_tys.len()
|
||||||
|
}
|
||||||
|
TypeEnum::TList { .. } | TypeEnum::TNDArray { .. } => {
|
||||||
|
return report_error(
|
||||||
|
concat!(
|
||||||
|
"ndarray index is list/array, but NumPy advanced (subset)",
|
||||||
|
"indexing is not supported yet"
|
||||||
|
),
|
||||||
|
slice.location,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// xxx: Could lead to suboptimal error message, as higher-dimensional indexing is not mentioned?!
|
||||||
|
self.constrain(
|
||||||
|
slice.custom.unwrap(),
|
||||||
|
self.primitives.int32,
|
||||||
|
&slice.location,
|
||||||
|
)?;
|
||||||
|
1
|
||||||
}
|
}
|
||||||
idx_tys.len()
|
|
||||||
} else {
|
|
||||||
// xxx: Could lead to suboptimal error message, as higher-dimensional indexing is not mentioned?!
|
|
||||||
self.constrain(
|
|
||||||
slice.custom.unwrap(),
|
|
||||||
self.primitives.int32,
|
|
||||||
&slice.location,
|
|
||||||
)?;
|
|
||||||
1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if *num_dims < num_idxs {
|
if *num_dims < num_idxs {
|
||||||
|
Loading…
Reference in New Issue
Block a user