luaur_analysis/methods/
unifier_try_unify_with_any_unifier.rs1use crate::functions::get_type_alt_j::get_type_id;
2use crate::functions::try_unify_with_any::try_unify_with_any;
3use crate::records::any_type::AnyType;
4use crate::records::extern_type::ExternType;
5use crate::records::never_type::NeverType;
6use crate::records::primitive_type::PrimitiveType;
7use crate::records::unifier::Unifier;
8use crate::records::unknown_type::UnknownType;
9use crate::records::variadic_type_pack::VariadicTypePack;
10use crate::type_aliases::error_type::ErrorType;
11use crate::type_aliases::type_id::TypeId;
12use alloc::vec::Vec;
13use luaur_common::macros::luau_assert::LUAU_ASSERT;
14
15impl Unifier {
16 pub fn try_unify_with_any_type_id_type_id(&mut self, sub_ty: TypeId, any_ty: TypeId) {
17 LUAU_ASSERT!(
18 !unsafe { get_type_id::<AnyType>(any_ty) }.is_null()
19 || !unsafe { get_type_id::<ErrorType>(any_ty) }.is_null()
20 || !unsafe { get_type_id::<UnknownType>(any_ty) }.is_null()
21 || !unsafe { get_type_id::<NeverType>(any_ty) }.is_null()
22 );
23
24 if !unsafe { get_type_id::<PrimitiveType>(sub_ty) }.is_null()
25 || !unsafe { get_type_id::<AnyType>(sub_ty) }.is_null()
26 || !unsafe { get_type_id::<ExternType>(sub_ty) }.is_null()
27 {
28 return;
29 }
30
31 let any_tp = unsafe {
32 (*self.types).add_type_pack_t(VariadicTypePack {
33 ty: any_ty,
34 hidden: false,
35 })
36 };
37 let mut queue: Vec<TypeId> = alloc::vec![sub_ty];
38
39 unsafe {
40 let shared_state = &mut *self.shared_state;
41 shared_state.temp_seen_ty.clear();
42 shared_state.temp_seen_tp.clear();
43 let seen_ty = &mut shared_state.temp_seen_ty as *mut _;
44 let seen_tp = &mut shared_state.temp_seen_tp as *mut _;
45
46 try_unify_with_any(
47 &mut queue,
48 self,
49 &mut *seen_ty,
50 &mut *seen_tp,
51 self.types,
52 any_ty,
53 any_tp,
54 );
55 }
56 }
57}