diff --git a/crates/erg_compiler/context/inquire.rs b/crates/erg_compiler/context/inquire.rs index 224e764b2..e070c0ddd 100644 --- a/crates/erg_compiler/context/inquire.rs +++ b/crates/erg_compiler/context/inquire.rs @@ -1329,7 +1329,7 @@ impl Context { )) } - fn validate_visibility( + pub(crate) fn validate_visibility( &self, ident: &Identifier, vi: &VarInfo, diff --git a/crates/erg_compiler/context/instantiate_spec.rs b/crates/erg_compiler/context/instantiate_spec.rs index 3ebaa7fd1..92a8e5bb3 100644 --- a/crates/erg_compiler/context/instantiate_spec.rs +++ b/crates/erg_compiler/context/instantiate_spec.rs @@ -551,12 +551,18 @@ impl Context { } } if let Some((typ, _)) = self.get_type_and_ctx(ident.inspect()) { + if let Some((_, vi)) = self.get_var_info(ident.inspect()) { + self.inc_ref(ident.inspect(), vi, ident, self); + } Ok(typ.clone()) } else if let Some(typ) = self .consts .get(ident.inspect()) .and_then(|v| self.convert_value_into_type(v.clone()).ok()) { + if let Some((_, vi)) = self.get_var_info(ident.inspect()) { + self.inc_ref(ident.inspect(), vi, ident, self); + } Ok(typ) } else if not_found_is_qvar { let tyvar = named_free_var(Str::rc(other), self.level, Constraint::Uninited);