get rid of nested tuple in type annotation helper function
This commit is contained in:
parent
862d205f67
commit
0bab477ab0
@ -420,15 +420,17 @@ impl TopLevelComposer {
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
// check if all are unique type vars
|
||||
let mut occured_type_var_id: HashSet<u32> = HashSet::new();
|
||||
let all_unique_type_var = type_vars.iter().all(|x| {
|
||||
let ty = unifier.get_ty(*x);
|
||||
if let TypeEnum::TVar { id, .. } = ty.as_ref() {
|
||||
occured_type_var_id.insert(*id)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
});
|
||||
let all_unique_type_var = {
|
||||
let mut occured_type_var_id: HashSet<u32> = HashSet::new();
|
||||
type_vars.iter().all(|x| {
|
||||
let ty = unifier.get_ty(*x);
|
||||
if let TypeEnum::TVar { id, .. } = ty.as_ref() {
|
||||
occured_type_var_id.insert(*id)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
};
|
||||
if !all_unique_type_var {
|
||||
return Err("expect unique type variables".into());
|
||||
}
|
||||
@ -439,7 +441,7 @@ impl TopLevelComposer {
|
||||
.map(|x| {
|
||||
// must be type var here after previous check
|
||||
let dup = duplicate_type_var(unifier, x);
|
||||
(dup.1, (dup.0).0)
|
||||
(dup.1, dup.0)
|
||||
})
|
||||
.collect_vec();
|
||||
|
||||
@ -620,9 +622,9 @@ impl TopLevelComposer {
|
||||
} else {
|
||||
// if not, create a duplicate
|
||||
let ty_copy = duplicate_type_var(unifier, ty);
|
||||
ty = ty_copy.0.0;
|
||||
ty = ty_copy.0;
|
||||
occured_type_var.insert(*id, ty);
|
||||
function_var_map.insert(ty_copy.1, ty_copy.0.0);
|
||||
function_var_map.insert(ty_copy.1, ty_copy.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
|
||||
Ok(TypeAnnotation::TypeVarKind(
|
||||
*id,
|
||||
// TODO: maybe not duplicate will also be fine here?
|
||||
duplicate_type_var(unifier, ty).0.0
|
||||
duplicate_type_var(unifier, ty).0
|
||||
))
|
||||
} else {
|
||||
Err("not a type variable identifier".into())
|
||||
@ -217,12 +217,13 @@ pub fn get_type_from_type_annotation_kinds(
|
||||
pub fn duplicate_type_var(
|
||||
unifier: &mut Unifier,
|
||||
type_var: Type
|
||||
) -> ((Type, u32), u32) {
|
||||
) -> (Type, u32, u32) {
|
||||
let ty = unifier.get_ty(type_var);
|
||||
if let TypeEnum::TVar { id, range, .. } = ty.as_ref() {
|
||||
let range = range.borrow();
|
||||
let range = range.as_slice();
|
||||
(unifier.get_fresh_var_with_range(range), *id)
|
||||
let dup = unifier.get_fresh_var_with_range(range);
|
||||
(dup.0, dup.1, *id)
|
||||
} else {
|
||||
unreachable!("must be type var here to be duplicated");
|
||||
}
|
||||
@ -253,7 +254,7 @@ pub fn make_self_type_annotation(
|
||||
.iter()
|
||||
.map(|(var_id, ty)| TypeAnnotation::TypeVarKind(
|
||||
*var_id,
|
||||
duplicate_type_var(unifier, *ty).0.0
|
||||
duplicate_type_var(unifier, *ty).0
|
||||
))
|
||||
.collect_vec()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user