1
//! The global functions a closure of the unit calls: redefining one later in
2
//! the unit would leave the closure on the old body.
3

            
4
use super::SymbolTable;
5
use super::homes::locked;
6
use crate::error::{Error, Result};
7

            
8
impl SymbolTable {
9
263414
    pub(crate) fn note_closure_deps<'a>(&self, names: impl Iterator<Item = &'a str>) {
10
263414
        locked(&self.homes)
11
263414
            .closure_deps
12
263414
            .extend(names.map(str::to_string));
13
263414
    }
14

            
15
    /// Drops what an earlier unit recorded, before this unit's start records
16
    /// the dependencies of the closures it carries.
17
2352063
    pub(crate) fn forget_closure_deps(&self) {
18
2352063
        locked(&self.homes).closure_deps.clear();
19
2352063
    }
20

            
21
38553
    pub(crate) fn reject_redefinition_after_closure(&self, name: &str) -> Result<()> {
22
38553
        match locked(&self.homes).closure_deps.contains(name) {
23
18934
            true => Err(Error::Compile(format!(
24
18934
                "{name}: redefined after a closure that calls it was created or used in this unit; \
25
18934
                 redefine it in a later unit, before the closure is used"
26
18934
            ))),
27
19619
            false => Ok(()),
28
        }
29
38553
    }
30
}