core: refactor to use PrimitiveDefinition::contains_id

This commit is contained in:
lyken 2024-06-06 12:54:22 +08:00
parent 38981445ae
commit b6ded9a869
2 changed files with 3 additions and 3 deletions

View File

@ -435,7 +435,7 @@ fn get_llvm_type<'ctx, G: CodeGenerator + ?Sized>(
let result = match &*ty_enum {
TObj { obj_id, fields, .. } => {
// check to avoid treating non-class primitives as classes
if obj_id.0 <= PrimitiveDefinition::max_id().0 {
if PrimitiveDefinition::contains_id(*obj_id) {
return match &*unifier.get_ty_immutable(ty) {
TObj { obj_id, params, .. } if *obj_id == PrimitiveDefinition::Option.id() => {
get_llvm_type(

View File

@ -35,8 +35,8 @@ impl PrimitiveDefinition {
return DefinitionId(self as usize);
}
pub fn max_id() -> DefinitionId {
Self::iter().map(|prim| prim.id()).max().unwrap()
pub fn contains_id(id: DefinitionId) -> bool {
Self::iter().any(|prim| prim.id() == id)
}
}