diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index 99ffa71..fe71a32 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -167,7 +167,10 @@ fn typechecking(input: ast::AST, handle: &mut Schala, comp: Option<&mut Unfinish let result = handle.type_context.typecheck(&input); comp.map(|comp| { - let artifact = TraceArtifact::new("type", format!("{:?}", result)); + let artifact = TraceArtifact::new("type", match result { + Ok(typestring) => typestring, + Err(err) => format!("Type error: {}", err) + }); comp.add_artifact(artifact); }); diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index e974ca6..39cbe5d 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -44,10 +44,23 @@ impl Type { fn arrow(a: Type, b: Type) -> Type { Type::Arrow(Box::new(a), Box::new(b)) } + + fn to_string(&self) -> String { + use self::Type::*; + use self::TypeConst::*; + match self { + Const(Unit) => format!("()"), + Const(Nat) => format!("Nat"), + Const(Int) => format!("Int"), + Const(Float) => format!("Float"), + Const(StringT) => format!("String"), + Const(Bool) => format!("Bool"), + Const(Order) => format!("Order"), + _ => format!("UNKNOWN TYPE"), + } + } } - - /* /// `Type` is parameterized by whether the type variables can be just universal, or universal or /// existential. @@ -146,7 +159,7 @@ impl<'a> TypeContext<'a> { for statement in ast.0.iter() { returned_type = self.typecheck_statement(statement.node()).map_err(|err| { err.msg })? } - Ok(format!("{:?}", returned_type)) + Ok(returned_type.to_string()) } fn typecheck_statement(&mut self, statement: &Statement) -> InferResult { @@ -156,7 +169,7 @@ impl<'a> TypeContext<'a> { } } - fn typecheck_decl(&mut self, decl: &Declaration) -> InferResult { + fn typecheck_decl(&mut self, _decl: &Declaration) -> InferResult { Ok(Type::Const(TypeConst::Unit)) } @@ -171,6 +184,11 @@ impl<'a> TypeContext<'a> { } fn typecheck_expr_type(&mut self, expr: &ExpressionType) -> InferResult { - Ok(Type::Const(TypeConst::Unit)) + use self::ExpressionType::*; + Ok(match expr { + NatLiteral(_) => Type::Const(TypeConst::Nat), + BoolLiteral(_) => Type::Const(TypeConst::Bool), + _ => Type::Const(TypeConst::Unit) + }) } }