Skip to main content

luaur_analysis/methods/
scope_inherit_refinements.rs

1use crate::functions::get_base_symbol::get_base_symbol;
2use crate::records::scope::Scope;
3use crate::records::symbol::Symbol;
4use crate::type_aliases::scope_ptr_scope::ScopePtr;
5
6impl Scope {
7    // Updates the `this` scope with the refinements from the `childScope`
8    // excluding ones that don't exist in `this` (Scope.cpp:226).
9    pub fn inherit_refinements(&mut self, child_scope: &ScopePtr) {
10        for (k, a) in unsafe { &(*child_scope).rvalue_refinements }.iter() {
11            if self.lookup_def_id(*k).is_some() {
12                *self.rvalue_refinements.get_or_insert(*k) = *a;
13            }
14        }
15
16        for (k, a) in unsafe { &(*child_scope).refinements } {
17            let symbol: Symbol = get_base_symbol(k);
18            if self.lookup_symbol(symbol).is_some() {
19                self.refinements.insert(k.clone(), *a);
20            }
21        }
22    }
23}