Skip to content

Commit

Permalink
Merge pull request #542 from jinko-core/refactor-typeid
Browse files Browse the repository at this point in the history
type_id: Refactor implementation
  • Loading branch information
CohenArthur authored Mar 22, 2022
2 parents 1ea1adc + a9ac141 commit b695d0b
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 b695d0b

Please sign in to comment.