This commit is contained in:
Shunsuke Shibayama 2022-12-05 17:21:46 +09:00
parent f21715c8c1
commit 4a0143302f
3 changed files with 15 additions and 0 deletions

View file

@ -127,6 +127,14 @@ impl<K, V> Dict<K, V> {
pub fn clear(&mut self) {
self.dict.clear();
}
/// remove all elements for which the predicate returns false
pub fn retain<F>(&mut self, f: F)
where
F: FnMut(&K, &mut V) -> bool,
{
self.dict.retain(f);
}
}
impl<K, V> IntoIterator for Dict<K, V> {

View file

@ -950,6 +950,12 @@ impl Context {
self.kind = kind;
}
pub(crate) fn clear_invalid_vars(&mut self) {
self.locals.retain(|_, v| v.t != Failure);
self.decls.retain(|_, v| v.t != Failure);
self.params.retain(|(_, v)| v.t != Failure);
}
pub fn pop(&mut self) -> Context {
if let Some(parent) = self.outer.as_mut() {
let parent = mem::take(parent);

View file

@ -1978,6 +1978,7 @@ impl ASTLowerer {
}
}
}
self.ctx.clear_invalid_vars();
self.ctx.check_decls().unwrap_or_else(|mut errs| {
self.errs.append(&mut errs);
});