From 9161e2751f04de3577f86ed5bee3e602d697953f Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 8 Oct 2017 23:45:38 -0700 Subject: [PATCH] (Janky) type inference for explicitly-type-annotated values --- 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 a218448..465aedb 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -74,6 +74,24 @@ pub enum SchalaType { Boolean, Unit, Function(Box, Box), + Bottom, +} + +impl SchalaType { + fn from_anno(anno: &TypeName) -> SchalaType { + use self::SchalaType::*; + + match anno { + &TypeName::Singleton { ref name, .. } => { + match name.as_ref().as_ref() { + "Int" => Integer, + "Bool" => Boolean, + _ => Bottom, + } + }, + _ => Bottom, + } + } } type TypeCheckResult = Result; @@ -115,6 +133,10 @@ impl TypeContext { use self::ExpressionType::*; Ok(match (&expr.0, &expr.1) { + (ref _t, &Some(ref anno)) => { + //TODO make this better, + SchalaType::from_anno(anno) + }, (&IntLiteral(_), _) => SchalaType::Integer, (&BoolLiteral(_), _) => SchalaType::Boolean, (&Variable(ref name), _) => self.symbol_table