From 76a9367284bac768ac845dee8fdc19f897de4d53 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 9 Oct 2017 11:42:53 -0700 Subject: [PATCH 1/2] String types --- src/schala_lang/type_check.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index 6ba73b1..964b0fa 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -111,6 +111,7 @@ pub enum TypeVariable { pub enum UVar { Integer, Float, + String, Boolean, Unit, Function(Box, Box), @@ -163,6 +164,7 @@ impl TypeContext { }, (&IntLiteral(_), _) => Univ(UVar::Integer), (&FloatLiteral(_), _) => Univ(UVar::Float), + (&StringLiteral(_), _) => Univ(UVar::String), (&BoolLiteral(_), _) => Univ(UVar::Boolean), (&Variable(ref name), _) => self.lookup(name).map(|entry| entry.type_var) .ok_or(format!("Couldn't find {}", name))?, From 33d0d49d308ae994bd8133601502d3235962f391 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 9 Oct 2017 12:26:25 -0700 Subject: [PATCH 2/2] Basic typing test --- src/schala_lang/type_check.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index 964b0fa..36bc13d 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -192,3 +192,25 @@ impl TypeContext { } } +#[cfg(test)] +mod tests { + use super::{TypeContext, TypeVariable, UVar}; + use super::TypeVariable::*; + use schala_lang::parsing::{parse, tokenize}; + + macro_rules! type_test { + ($input:expr, $correct:expr) => { + { + let mut tc = TypeContext::new(); + let ast = parse(tokenize($input)).0.unwrap() ; + assert_eq!($correct, tc.type_check(&ast).unwrap()) + } + } + } + + #[test] + fn basic_inference() { + type_test!("30", Univ(UVar::Integer)) + } +} +