diff --git a/crates/erg_compiler/context/inquire.rs b/crates/erg_compiler/context/inquire.rs index 77c1c1023..7c7c03cd6 100644 --- a/crates/erg_compiler/context/inquire.rs +++ b/crates/erg_compiler/context/inquire.rs @@ -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(); } @@ -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 { @@ -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 { @@ -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)> { diff --git a/crates/erg_compiler/context/register.rs b/crates/erg_compiler/context/register.rs index 2198ed822..8dce4e04d 100644 --- a/crates/erg_compiler/context/register.rs +++ b/crates/erg_compiler/context/register.rs @@ -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)