Skip to content

Commit

Permalink
type_id: Refactor implementation
Browse files Browse the repository at this point in the history
Co-authored-by: n1tram1 <martin.schmidt@epita.fr>
  • Loading branch information
CohenArthur and n1tram1 committed Mar 20, 2022
1 parent 10149dc commit a9ac141
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/typechecker/type_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,29 @@ impl TypeId {
/// Add a generic type to a consumed [`TypeId`]'s generic list
pub fn with_generic(self, generic: TypeId) -> TypeId {
match self {
TypeId::Type { id, generics } => TypeId::Type {
id,
generics: [generics, [generic].to_vec()].concat(),
},
TypeId::Type { id, generics } => {
let mut new_generics = generics;
new_generics.push(generic);

TypeId::Type {
id,
generics: new_generics,
}
}
TypeId::Functor {
generics,
arg_types,
return_type,
} => TypeId::Functor {
generics: [generics, [generic].to_vec()].concat(),
arg_types,
return_type,
},
} => {
let mut new_generics = generics;
new_generics.push(generic);

TypeId::Functor {
generics: new_generics,
arg_types,
return_type,
}
}
}
}

Expand All @@ -97,11 +107,16 @@ impl TypeId {
generics,
arg_types,
return_type,
} => TypeId::Functor {
generics,
arg_types: [arg_types, [arg].to_vec()].concat(),
return_type,
},
} => {
let mut new_args = arg_types;
new_args.push(arg);

TypeId::Functor {
generics,
arg_types: new_args,
return_type,
}
}
}
}

Expand Down

0 comments on commit a9ac141

Please sign in to comment.