From 955c0731744c07b0e168461d7c11cc0a69b0950f Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 13 Nov 2018 02:39:02 -0800 Subject: [PATCH] Got typechecker unused errors down to one --- schala-lang/language/src/typechecking.rs | 42 ++++++++++-------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 453bba0..437622f 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -60,7 +60,7 @@ impl Type { fn skolemize(&self) -> Type { match self { Type::Var(TVar::Univ(uvar)) => Type::Var(uvar.clone()), - Type::Var(TVar::Exist(evar)) => Type::Var(UVar(Rc::new(format!("sk")))), + Type::Var(TVar::Exist(_)) => Type::Var(UVar(Rc::new(format!("sk")))), Type::Const(ref c) => Type::Const(c.clone()), Type::Arrow(a, b) => Type::Arrow( Box::new(a.skolemize()), @@ -73,7 +73,7 @@ impl Type { impl TypeIdentifier { fn to_monotype(&self) -> Type { match self { - TypeIdentifier::Tuple(items) => unimplemented!(), + TypeIdentifier::Tuple(_) => Type::Const(TConst::Nat), TypeIdentifier::Singleton(TypeSingletonName { name, .. }) => { match &name[..] { "Nat" => Type::Const(TConst::Nat), @@ -81,7 +81,7 @@ impl TypeIdentifier { "Float" => Type::Const(TConst::Float), "Bool" => Type::Const(TConst::Bool), "String" => Type::Const(TConst::StringT), - _ => unimplemented!() + _ => Type::Const(TConst::Nat), } } } @@ -105,12 +105,6 @@ impl TConst { } } -#[derive(Debug, Clone)] -struct PolyType { - vars: Vec>, - ty: Type<()> -} - impl<'a> TypeContext<'a> { pub fn new() -> TypeContext<'a> { TypeContext { @@ -129,11 +123,7 @@ impl<'a> TypeContext<'a> { impl<'a> TypeContext<'a> { fn infer_ast(&mut self, ast: &AST) -> InferResult> { - let mut output = Type::Const(TConst::Unit); - for statement in ast.0.iter() { - output = self.infer_statement(statement)?; - } - Ok(output) + self.infer_block(&ast.0) } fn infer_statement(&mut self, stmt: &Statement) -> InferResult> { @@ -154,7 +144,7 @@ impl<'a> TypeContext<'a> { } } - fn infer_decl(&mut self, expr: &Declaration) -> InferResult> { + fn infer_decl(&mut self, _decl: &Declaration) -> InferResult> { Ok(Type::Const(TConst::user("unimplemented"))) } @@ -186,29 +176,33 @@ impl<'a> TypeContext<'a> { } }, - Lambda { params, type_anno, body } => { + Lambda { params, .. } => { - let arg_type = unimplemented!(); - let result_type = unimplemented!(); + let _arg_type = match ¶ms[0] { + (_, Some(type_anno)) => type_anno.to_monotype().to_tvar(), + (_, None) => self.allocate_existential(), + }; + //let _result_type = unimplemented!(); + return TypeError::new("Unimplemented"); - Type::Arrow(Box::new(arg_type), Box::new(result_type)) + //Type::Arrow(Box::new(arg_type), Box::new(result_type)) } _ => Type::Const(TConst::user("unimplemented")) }) } fn infer_if_expr(&mut self, discriminator: &Discriminator, body: &IfExpressionBody) -> InferResult> { - let test = match discriminator { + let _test = match discriminator { Discriminator::Simple(expr) => expr, _ => return TypeError::new("Dame desu") }; - let (then_clause, maybe_else_clause) = match body { + let (_then_clause, _maybe_else_clause) = match body { IfExpressionBody::SimpleConditional(a, b) => (a, b), _ => return TypeError::new("Dont work") }; - unimplemented!() + TypeError::new("Not implemented") } fn infer_block(&mut self, block: &Block) -> InferResult> { @@ -219,8 +213,8 @@ impl<'a> TypeContext<'a> { Ok(output) } - fn unify(&mut self, t1: &Type, t2: &Type) -> InferResult> { - unimplemented!() + fn unify(&mut self, _t1: &Type, _t2: &Type) -> InferResult> { + TypeError::new("not implemented") } fn allocate_existential(&mut self) -> Type {