diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 5f287f3..bf6a56a 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -25,7 +25,9 @@ enum TConst { User(Rc), Unit, Nat, - Int + Int, + Float, + StringT, } impl TConst { @@ -80,6 +82,8 @@ impl TypeContext { use self::ExpressionType::*; match expr_type { NatLiteral(_) => Ok(MonoType::Const(TConst::Nat)), + FloatLiteral(_) => Ok(MonoType::Const(TConst::Float)), + StringLiteral(_) => Ok(MonoType::Const(TConst::StringT)), _ => Ok(MonoType::Const(TConst::user("unimplemented"))) } } @@ -88,6 +92,26 @@ impl TypeContext { #[cfg(test)] mod tests { use super::*; + + fn parse(input: &str) -> AST { + let tokens: Vec<::tokenizing::Token> = ::tokenizing::tokenize(input); + let mut parser = ::parsing::Parser::new(tokens); + parser.parse().unwrap() + } + + macro_rules! type_test { + ($input:expr, $correct:expr) => { + { + let mut tc = TypeContext::new(); + let ast = parse($input); + tc.add_symbols(&ast); + assert_eq!($correct, tc.type_check(&ast).unwrap()) + } + } + } + + + #[test] fn basic_inference() {