(Janky) type inference for explicitly-type-annotated values
This commit is contained in:
parent
60fc9fd7e1
commit
9161e2751f
@ -74,6 +74,24 @@ pub enum SchalaType {
|
|||||||
Boolean,
|
Boolean,
|
||||||
Unit,
|
Unit,
|
||||||
Function(Box<SchalaType>, Box<SchalaType>),
|
Function(Box<SchalaType>, Box<SchalaType>),
|
||||||
|
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<SchalaType, String>;
|
type TypeCheckResult = Result<SchalaType, String>;
|
||||||
@ -115,6 +133,10 @@ impl TypeContext {
|
|||||||
use self::ExpressionType::*;
|
use self::ExpressionType::*;
|
||||||
|
|
||||||
Ok(match (&expr.0, &expr.1) {
|
Ok(match (&expr.0, &expr.1) {
|
||||||
|
(ref _t, &Some(ref anno)) => {
|
||||||
|
//TODO make this better,
|
||||||
|
SchalaType::from_anno(anno)
|
||||||
|
},
|
||||||
(&IntLiteral(_), _) => SchalaType::Integer,
|
(&IntLiteral(_), _) => SchalaType::Integer,
|
||||||
(&BoolLiteral(_), _) => SchalaType::Boolean,
|
(&BoolLiteral(_), _) => SchalaType::Boolean,
|
||||||
(&Variable(ref name), _) => self.symbol_table
|
(&Variable(ref name), _) => self.symbol_table
|
||||||
|
Loading…
Reference in New Issue
Block a user