Skip to content

Commit

Permalink
fix: import bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Jun 21, 2023
1 parent d456234 commit 9891831
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions crates/erg_compiler/context/inquire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ pub enum SubstituteResult {
}

impl Context {
pub(crate) fn get_ctx_from_path(&self, path: &Path) -> Option<&Context> {
pub(crate) fn mod_registered(&self, path: &Path) -> bool {
self.shared.is_some() && self.promises().is_registered(path)
}

pub(crate) fn get_mod_with_path(&self, path: &Path) -> Option<&Context> {
if self.module_path() == Some(path) {
return self.get_module();
}
Expand Down Expand Up @@ -2485,15 +2489,6 @@ impl Context {
}
}

pub(crate) fn get_mod_with_path(&self, path: &Path) -> Option<&Context> {
(self.cfg.input.path() == Some(path)) // module itself
.then_some(self)
.or(self
.mod_cache()
.raw_ref_ctx(path)
.map(|mod_ctx| &mod_ctx.context))
}

// FIXME: 現在の実装だとimportしたモジュールはどこからでも見れる
pub(crate) fn get_mod(&self, name: &str) -> Option<&Context> {
if name == "module" && ERG_MODE {
Expand All @@ -2507,7 +2502,7 @@ impl Context {
}

pub fn get_mod_with_t(&self, mod_t: &Type) -> Option<&Context> {
self.get_ctx_from_path(&self.get_path_with_mod_t(mod_t)?)
self.get_mod_with_path(&self.get_path_with_mod_t(mod_t)?)
}

pub fn get_path_with_mod_t(&self, mod_t: &Type) -> Option<PathBuf> {
Expand Down Expand Up @@ -2600,7 +2595,7 @@ impl Context {
} else if &namespace[..] == "module" {
return self.get_module();
}
self.get_ctx_from_path(self.get_namespace_path(namespace)?.as_path())
self.get_mod_with_path(self.get_namespace_path(namespace)?.as_path())
}

pub(crate) fn get_mono_type(&self, name: &Str) -> Option<(&Type, &Context)> {
Expand Down
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ impl Context {
let graph = &self.shared.as_ref().unwrap().graph;
graph.inc_ref(referrer, path.clone());
}
if self.get_mod_with_path(&path).is_some() {
if self.mod_registered(&path) {
return Ok(path);
}
self.build_erg_mod(path, __name__, loc)
Expand Down

0 comments on commit 9891831

Please sign in to comment.