mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 13:11:11 +00:00
Add Context::resolve_ctx_vars
This commit is contained in:
parent
929f777960
commit
0af0241d34
2 changed files with 25 additions and 0 deletions
|
@ -957,6 +957,7 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// unlike `pop`, `outer` must be `None`.
|
||||||
pub fn pop_mod(&mut self) -> Option<Context> {
|
pub fn pop_mod(&mut self) -> Option<Context> {
|
||||||
if self.outer.is_some() {
|
if self.outer.is_some() {
|
||||||
log!(err "not in the top-level context");
|
log!(err "not in the top-level context");
|
||||||
|
|
|
@ -696,6 +696,7 @@ impl Context {
|
||||||
errs.extend(es);
|
errs.extend(es);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.resolve_ctx_vars();
|
||||||
if errs.is_empty() {
|
if errs.is_empty() {
|
||||||
Ok(hir)
|
Ok(hir)
|
||||||
} else {
|
} else {
|
||||||
|
@ -703,6 +704,29 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resolve_ctx_vars(&mut self) {
|
||||||
|
let mut locals = mem::take(&mut self.locals);
|
||||||
|
let mut params = mem::take(&mut self.params);
|
||||||
|
let mut methods_list = mem::take(&mut self.methods_list);
|
||||||
|
for (name, vi) in locals.iter_mut() {
|
||||||
|
if let Ok(t) = self.deref_tyvar(mem::take(&mut vi.t), Variance::Covariant, name.loc()) {
|
||||||
|
vi.t = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (name, vi) in params.iter_mut() {
|
||||||
|
let loc = name.as_ref().map(|n| n.loc()).unwrap_or_default();
|
||||||
|
if let Ok(t) = self.deref_tyvar(mem::take(&mut vi.t), Variance::Covariant, loc) {
|
||||||
|
vi.t = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (_, methods) in methods_list.iter_mut() {
|
||||||
|
methods.resolve_ctx_vars();
|
||||||
|
}
|
||||||
|
self.locals = locals;
|
||||||
|
self.params = params;
|
||||||
|
self.methods_list = methods_list;
|
||||||
|
}
|
||||||
|
|
||||||
fn resolve_expr_t(&self, expr: &mut hir::Expr) -> TyCheckResult<()> {
|
fn resolve_expr_t(&self, expr: &mut hir::Expr) -> TyCheckResult<()> {
|
||||||
match expr {
|
match expr {
|
||||||
hir::Expr::Lit(_) => Ok(()),
|
hir::Expr::Lit(_) => Ok(()),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue