hm-inference #6

Merged
sb10q merged 136 commits from hm-inference into master 2021-08-19 11:46:50 +08:00
1 changed files with 12 additions and 5 deletions
Showing only changes of commit c913fb28bd - Show all commits

View File

@ -81,7 +81,7 @@ pub enum TypeEnum {
id: u32,
},
TSeq {
map: VarMap,
map: Mapping<i32>,
},
TTuple {
ty: Vec<Type>,
@ -274,16 +274,18 @@ impl Unifier {
self.set_a_to_b(a, b);
}
TypeEnum::TTuple { ty: types } => {
let len = types.len() as u32;
let len = types.len() as i32;
for (k, v) in map1.iter() {
if *k >= len {
// handle negative index
let ind = if *k < 0 { len + *k } else { *k };
if ind >= len || ind < 0 {
return Err(format!(
"Tuple index out of range. (Length: {}, Index: {})",
types.len(),
k
));
}
self.unify(*v, types[*k as usize])?;
self.unify(*v, types[ind as usize])?;
}
self.set_a_to_b(a, b);
}
@ -516,7 +518,7 @@ impl Unifier {
TypeEnum::TVar { .. } => {
// TODO: occur check for bounds...
}
TypeEnum::TSeq { map } | TypeEnum::TObj { params: map, .. } => {
TypeEnum::TSeq { map } => {
for t in map.values() {
self.occur_check(a, *t)?;
}
@ -534,6 +536,11 @@ impl Unifier {
self.occur_check(a, *t)?;
}
}
TypeEnum::TObj { params: map, .. } => {
for t in map.values() {
self.occur_check(a, *t)?;
}
}
TypeEnum::TCall { calls } => {
for t in calls
.iter()