Skip to main content

luaur_analysis/methods/
unifier_try_unify_primitives.rs

1use crate::functions::get_type_alt_j::get_type_id;
2use crate::records::primitive_type::PrimitiveType;
3use crate::records::type_mismatch::TypeMismatch;
4use crate::records::unifier::Unifier;
5use crate::type_aliases::type_error_data::TypeErrorData;
6use crate::type_aliases::type_id::TypeId;
7use alloc::string::String;
8
9impl Unifier {
10    pub fn unifier_try_unify_primitives(&mut self, sub_ty: TypeId, super_ty: TypeId) {
11        let super_prim = unsafe { get_type_id::<PrimitiveType>(super_ty) };
12        let sub_prim = unsafe { get_type_id::<PrimitiveType>(sub_ty) };
13
14        if super_prim.is_null() || sub_prim.is_null() {
15            self.ice_string("passed non primitive types to unifyPrimitives");
16            return;
17        }
18
19        if unsafe { (*super_prim).r#type != (*sub_prim).r#type } {
20            let context = self.unifier_mismatch_context();
21            self.report_error_location_type_error_data(
22                self.location,
23                TypeErrorData::TypeMismatch(TypeMismatch {
24                    wanted_type: super_ty,
25                    given_type: sub_ty,
26                    reason: String::new(),
27                    error: None,
28                    context,
29                }),
30            );
31        }
32    }
33}