Lines
100 %
Functions
Branches
//! The global functions a closure of the unit calls: redefining one later in
//! the unit would leave the closure on the old body.
use super::SymbolTable;
use super::homes::locked;
use crate::error::{Error, Result};
impl SymbolTable {
pub(crate) fn note_closure_deps<'a>(&self, names: impl Iterator<Item = &'a str>) {
locked(&self.homes)
.closure_deps
.extend(names.map(str::to_string));
}
/// Drops what an earlier unit recorded, before this unit's start records
/// the dependencies of the closures it carries.
pub(crate) fn forget_closure_deps(&self) {
locked(&self.homes).closure_deps.clear();
pub(crate) fn reject_redefinition_after_closure(&self, name: &str) -> Result<()> {
match locked(&self.homes).closure_deps.contains(name) {
true => Err(Error::Compile(format!(
"{name}: redefined after a closure that calls it was created or used in this unit; \
redefine it in a later unit, before the closure is used"
))),
false => Ok(()),