Merge branch 'master' of github.com:neunenak/schala

This commit is contained in:
greg 2017-10-10 01:09:27 -07:00
commit 32e077c407

View File

@ -111,6 +111,7 @@ pub enum TypeVariable {
pub enum UVar {
Integer,
Float,
String,
Boolean,
Unit,
Function(Box<TypeVariable>, Box<TypeVariable>),
@ -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))?,
@ -209,3 +211,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))
}
}