Skip to main content

luaur_analysis/methods/
normalizer_intersection_of_tops.rs

1use crate::functions::get_type_alt_j::get_type_id;
2use crate::records::any_type::AnyType;
3use crate::records::never_type::NeverType;
4use crate::records::normalizer::Normalizer;
5use crate::records::unknown_type::UnknownType;
6use crate::type_aliases::type_id::TypeId;
7
8impl Normalizer {
9    pub fn intersection_of_tops(&mut self, here: TypeId, there: TypeId) -> TypeId {
10        self.consume_fuel();
11
12        let here_is_never = !unsafe { get_type_id::<NeverType>(here).is_null() };
13        let there_is_never = !unsafe { get_type_id::<NeverType>(there).is_null() };
14        let here_is_any = !unsafe { get_type_id::<AnyType>(here).is_null() };
15        let there_is_any = !unsafe { get_type_id::<AnyType>(there).is_null() };
16
17        if here_is_never || there_is_never {
18            return unsafe { (*self.builtin_types).neverType };
19        }
20
21        if here_is_any || there_is_any {
22            return unsafe { (*self.builtin_types).anyType };
23        }
24
25        unsafe { (*self.builtin_types).unknownType }
26    }
27}