From 9e0f8b8a14ba04830b40733eae0f1848ba9ab8d2 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 17 May 2018 02:29:17 -0700 Subject: [PATCH] InferError --- schala-lang/src/typechecking.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index 5252499..ec2f459 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -238,9 +238,11 @@ impl TypeContext { pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult { let ref block = ast.0; let mut infer = Infer::new(); - let output = infer.infer_block(block)?; - - Ok(format!("{:?}", output)) + let output = infer.infer_block(block); + match 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, MonoType), + UnknownIdentifier(Rc) +} + impl Infer { fn new() -> Infer { Infer { } } - fn infer_block(&mut self, block: &Vec) -> TypeResult { + fn infer_block(&mut self, block: &Vec) -> Result { Ok(MonoType::Const(TypeConst::Unit)) } }