InferError

This commit is contained in:
greg 2018-05-17 02:29:17 -07:00
parent 7121624f77
commit 9e0f8b8a14

View File

@ -238,9 +238,11 @@ impl TypeContext {
pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult<String> { pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult<String> {
let ref block = ast.0; let ref block = ast.0;
let mut infer = Infer::new(); let mut infer = Infer::new();
let output = infer.infer_block(block)?; let output = infer.infer_block(block);
match output {
Ok(format!("{:?}", output)) Ok(s) => Ok(format!("{:?}", s)),
Err(s) => Err(format!("Error: {:?}", s))
}
} }
} }
@ -250,12 +252,19 @@ struct Infer {
} }
#[derive(Debug)]
enum InferError {
CannotUnify(MonoType, MonoType),
OccursCheckFailed(Rc<String>, MonoType),
UnknownIdentifier(Rc<String>)
}
impl Infer { impl Infer {
fn new() -> Infer { fn new() -> Infer {
Infer { } Infer { }
} }
fn infer_block(&mut self, block: &Vec<parsing::Statement>) -> TypeResult<MonoType> { fn infer_block(&mut self, block: &Vec<parsing::Statement>) -> Result<MonoType, InferError> {
Ok(MonoType::Const(TypeConst::Unit)) Ok(MonoType::Const(TypeConst::Unit))
} }
} }