core/typedef: Add Type::obj_id to replace get_obj_id

David Mak 2024-03-27 10:36:02 +08:00
parent 0636398f3c
commit 160cfa500a
1 changed files with 12 additions and 6 deletions

View File

@ -61,15 +61,21 @@ pub enum RecordKey {
}
impl Type {
// a wrapper function for cleaner code so that we don't need to
// write this long pattern matching just to get the field `obj_id`
pub fn get_obj_id(self, unifier: &Unifier) -> DefinitionId {
if let TypeEnum::TObj { obj_id, .. } = unifier.get_ty_immutable(self).as_ref() {
*obj_id
/// Wrapper function for cleaner code so that we don't need to write this long pattern matching
/// just to get the field `obj_id`.
#[must_use]
pub fn obj_id(self, unifier: &Unifier) -> Option<DefinitionId> {
if let TypeEnum::TObj { obj_id, .. } = &*unifier.get_ty_immutable(self) {
Some(*obj_id)
} else {
unreachable!("expect a object type")
None
}
}
#[deprecated = "Prefer using `Type::obj_id` instead to handle non-TObj cases."]
pub fn get_obj_id(self, unifier: &Unifier) -> DefinitionId {
self.obj_id(unifier).expect("expect a object type")
}
}
impl From<&RecordKey> for StrRef {