luaur_analysis/methods/
unifier_try_unify_negations.rs1use crate::functions::get_type_alt_j::get_type_id;
2use crate::records::negation_type::NegationType;
3use crate::records::normalization_too_complex::NormalizationTooComplex;
4use crate::records::type_mismatch::TypeMismatch;
5use crate::records::unifier::Unifier;
6use crate::type_aliases::type_error_data::TypeErrorData;
7use crate::type_aliases::type_id::TypeId;
8use alloc::string::{String, ToString};
9
10impl Unifier {
11 pub fn unifier_try_unify_negations(&mut self, sub_ty: TypeId, super_ty: TypeId) {
12 if unsafe { get_type_id::<NegationType>(sub_ty) }.is_null()
13 && unsafe { get_type_id::<NegationType>(super_ty) }.is_null()
14 {
15 self.ice_string("tryUnifyNegations superTy or subTy must be a negation type");
16 }
17
18 let sub_norm = unsafe { (*self.normalizer).normalize(sub_ty) };
19 let super_norm = unsafe { (*self.normalizer).normalize(super_ty) };
20
21 let mut state = self.unifier_make_child_unifier();
22 state.unifier_try_unify_normalized_types(
23 sub_ty,
24 super_ty,
25 &sub_norm,
26 &super_norm,
27 String::new(),
28 None,
29 );
30 if state.errors.is_empty() {
31 let context = self.unifier_mismatch_context();
32 self.report_error_location_type_error_data(
33 self.location,
34 TypeErrorData::TypeMismatch(TypeMismatch {
35 wanted_type: super_ty,
36 given_type: sub_ty,
37 reason: String::new(),
38 error: None,
39 context,
40 }),
41 );
42 }
43 }
44}