forked from M-Labs/nac3
Compare commits
2 Commits
b0526ba29f
...
ad90a6cf9a
Author | SHA1 | Date | |
---|---|---|---|
|
ad90a6cf9a | ||
|
e858ca686f |
@ -249,6 +249,8 @@ impl Inferencer<'_> {
|
|||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
match &*self.unifier.get_ty_immutable(ret_ty) {
|
match &*self.unifier.get_ty_immutable(ret_ty) {
|
||||||
|
// For an object type, only allow a select few primitive types.
|
||||||
|
// (Note: you may wish to also allow strings if that’s acceptable.)
|
||||||
TypeEnum::TObj { .. } => [
|
TypeEnum::TObj { .. } => [
|
||||||
self.primitives.int32,
|
self.primitives.int32,
|
||||||
self.primitives.int64,
|
self.primitives.int64,
|
||||||
@ -259,9 +261,25 @@ impl Inferencer<'_> {
|
|||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.any(|allowed_ty| self.unifier.unioned(ret_ty, *allowed_ty)),
|
.any(|allowed_ty| self.unifier.unioned(ret_ty, *allowed_ty)),
|
||||||
TypeEnum::TTuple { ty, .. } => ty.iter().all(|t| self.check_return_value_ty(*t)),
|
|
||||||
|
// For a tuple, first check that none of the elements are lists or NDArrays.
|
||||||
|
// Then, recursively ensure that each element is also a safe return type.
|
||||||
|
TypeEnum::TTuple { ty, .. } => {
|
||||||
|
for &elem_ty in ty {
|
||||||
|
if let TypeEnum::TObj { obj_id, .. } = &*self.unifier.get_ty_immutable(elem_ty) {
|
||||||
|
// Here we try to get the concrete identifier of the object.
|
||||||
|
if *obj_id == PrimDef::List.id() || *obj_id == PrimDef::NDArray.id() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Recursively check that all tuple element types are acceptable.
|
||||||
|
ty.iter().all(|t| self.check_return_value_ty(*t))
|
||||||
|
},
|
||||||
|
|
||||||
|
// Any other type is disallowed.
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user