forked from M-Labs/nac3
added return type check
This commit is contained in:
parent
09c9218852
commit
d484fa1e5c
@ -31,6 +31,7 @@ pub struct Inferencer<'a> {
|
|||||||
pub variable_mapping: HashMap<String, Type>,
|
pub variable_mapping: HashMap<String, Type>,
|
||||||
pub calls: &'a mut Vec<Rc<Call>>,
|
pub calls: &'a mut Vec<Rc<Call>>,
|
||||||
pub primitives: &'a PrimitiveStore,
|
pub primitives: &'a PrimitiveStore,
|
||||||
|
pub return_type: Option<Type>
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NaiveFolder();
|
struct NaiveFolder();
|
||||||
@ -106,6 +107,20 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::StmtKind::AnnAssign { .. } | ast::StmtKind::Expr { .. } => {}
|
ast::StmtKind::AnnAssign { .. } | ast::StmtKind::Expr { .. } => {}
|
||||||
|
ast::StmtKind::Return { value } => {
|
||||||
|
match (value, self.return_type) {
|
||||||
|
(Some(v), Some(v1)) => {
|
||||||
|
self.unifier.unify(v.custom.unwrap(), v1)?;
|
||||||
|
}
|
||||||
|
(Some(_), None) => {
|
||||||
|
return Err("Unexpected return value".to_string());
|
||||||
|
}
|
||||||
|
(None, Some(_)) => {
|
||||||
|
return Err("Expected return value".to_string());
|
||||||
|
}
|
||||||
|
(None, None) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => return Err("Unsupported statement type".to_string()),
|
_ => return Err("Unsupported statement type".to_string()),
|
||||||
};
|
};
|
||||||
Ok(stmt)
|
Ok(stmt)
|
||||||
@ -227,6 +242,7 @@ impl<'a> Inferencer<'a> {
|
|||||||
variable_mapping,
|
variable_mapping,
|
||||||
calls: self.calls,
|
calls: self.calls,
|
||||||
primitives: self.primitives,
|
primitives: self.primitives,
|
||||||
|
return_type: self.return_type
|
||||||
};
|
};
|
||||||
let fun = FunSignature {
|
let fun = FunSignature {
|
||||||
args: fn_args
|
args: fn_args
|
||||||
@ -275,6 +291,7 @@ impl<'a> Inferencer<'a> {
|
|||||||
variable_mapping,
|
variable_mapping,
|
||||||
calls: self.calls,
|
calls: self.calls,
|
||||||
primitives: self.primitives,
|
primitives: self.primitives,
|
||||||
|
return_type: self.return_type
|
||||||
};
|
};
|
||||||
let elt = new_context.fold_expr(elt)?;
|
let elt = new_context.fold_expr(elt)?;
|
||||||
let generator = generators.pop().unwrap();
|
let generator = generators.pop().unwrap();
|
||||||
|
@ -123,6 +123,7 @@ impl TestEnvironment {
|
|||||||
variable_mapping: Default::default(),
|
variable_mapping: Default::default(),
|
||||||
calls: &mut self.calls,
|
calls: &mut self.calls,
|
||||||
primitives: &mut self.primitives,
|
primitives: &mut self.primitives,
|
||||||
|
return_type: None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ impl Unifier {
|
|||||||
}
|
}
|
||||||
TypeEnum::TObj { obj_id, params, .. } => {
|
TypeEnum::TObj { obj_id, params, .. } => {
|
||||||
let name = obj_to_name(*obj_id);
|
let name = obj_to_name(*obj_id);
|
||||||
if params.len() > 0 {
|
if !params.is_empty() {
|
||||||
let mut params = params
|
let mut params = params
|
||||||
.values()
|
.values()
|
||||||
.map(|v| self.stringify(*v, obj_to_name, var_to_name));
|
.map(|v| self.stringify(*v, obj_to_name, var_to_name));
|
||||||
|
Loading…
Reference in New Issue
Block a user