diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs index 19b0e655b7c..4e9f4c8ed02 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs @@ -819,7 +819,7 @@ pub(crate) fn resolve_method_name( let type_info_prefix = ctx .namespace() .prepend_module_path(&call_path_binding.inner.prefixes); - ctx.namespace().lookup_submodule_from_absolute_path( + ctx.namespace().root_module().lookup_submodule( handler, engines, &type_info_prefix, diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs index 23ff00f7894..c127186d958 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs @@ -81,7 +81,8 @@ pub(crate) fn struct_instantiation( // find the module that the struct decl is in let type_info_prefix = ctx.namespace().prepend_module_path(prefixes); ctx.namespace() - .lookup_submodule_from_absolute_path(handler, engines, &type_info_prefix)?; + .root_module() + .lookup_submodule(handler, engines, &type_info_prefix)?; // resolve the type of the struct decl let type_id = ctx diff --git a/sway-core/src/semantic_analysis/namespace/namespace.rs b/sway-core/src/semantic_analysis/namespace/namespace.rs index 0bd55608e21..17f5a50a996 100644 --- a/sway-core/src/semantic_analysis/namespace/namespace.rs +++ b/sway-core/src/semantic_analysis/namespace/namespace.rs @@ -4,7 +4,7 @@ use super::{ module::Module, root::Root, submodule_namespace::SubmoduleNamespace, ModulePath, ModulePathBuf, }; -use sway_error::handler::{ErrorEmitted, Handler}; +use sway_error::handler::Handler; use sway_types::span::Span; /// The set of items that represent the namespace context passed throughout type checking. @@ -118,15 +118,6 @@ impl Namespace { .unwrap() } - pub fn lookup_submodule_from_absolute_path( - &self, - handler: &Handler, - engines: &Engines, - path: &ModulePath, - ) -> Result<&Module, ErrorEmitted> { - self.root.module.lookup_submodule(handler, engines, path) - } - /// Returns true if the current module being checked is a direct or indirect submodule of /// the module given by the `absolute_module_path`. /// diff --git a/sway-core/src/semantic_analysis/symbol_resolve_context.rs b/sway-core/src/semantic_analysis/symbol_resolve_context.rs index 03661429ae5..7a9155a193a 100644 --- a/sway-core/src/semantic_analysis/symbol_resolve_context.rs +++ b/sway-core/src/semantic_analysis/symbol_resolve_context.rs @@ -187,7 +187,7 @@ impl<'a> SymbolResolveContext<'a> { resolve_call_path( handler, self.engines(), - self.namespace(), + self.namespace().root(), &self.namespace().mod_path, call_path, self.self_type(), diff --git a/sway-core/src/semantic_analysis/type_check_context.rs b/sway-core/src/semantic_analysis/type_check_context.rs index 9affc746089..953620096c6 100644 --- a/sway-core/src/semantic_analysis/type_check_context.rs +++ b/sway-core/src/semantic_analysis/type_check_context.rs @@ -721,7 +721,7 @@ impl<'a> TypeCheckContext<'a> { resolve_call_path( handler, self.engines(), - self.namespace(), + self.namespace().root(), &self.namespace().mod_path, call_path, self.self_type(), @@ -739,7 +739,7 @@ impl<'a> TypeCheckContext<'a> { resolve_call_path( handler, self.engines(), - self.namespace(), + self.namespace().root(), self.namespace().mod_path(), call_path, self.self_type(), @@ -768,7 +768,7 @@ impl<'a> TypeCheckContext<'a> { } // grab the local module - let local_module = self.namespace().lookup_submodule_from_absolute_path( + let local_module = self.namespace().root_module().lookup_submodule( handler, self.engines(), &self.namespace().mod_path, @@ -796,7 +796,7 @@ impl<'a> TypeCheckContext<'a> { .unwrap_or_else(|err| type_engine.insert(self.engines, TypeInfo::ErrorRecovery(err), None)); // grab the module where the type itself is declared - let type_module = self.namespace().lookup_submodule_from_absolute_path( + let type_module = self.namespace().root_module().lookup_submodule( handler, self.engines(), item_prefix, diff --git a/sway-core/src/semantic_analysis/type_resolve.rs b/sway-core/src/semantic_analysis/type_resolve.rs index 14f33d2dc53..bfa7c9261ac 100644 --- a/sway-core/src/semantic_analysis/type_resolve.rs +++ b/sway-core/src/semantic_analysis/type_resolve.rs @@ -11,7 +11,7 @@ use crate::{ CallPath, QualifiedCallPath, }, monomorphization::type_decl_opt_to_type_id, - namespace::{Module, ModulePath, ResolvedDeclaration, ResolvedTraitImplItem}, + namespace::{Module, ModulePath, ResolvedDeclaration, ResolvedTraitImplItem, Root}, type_system::SubstTypes, EnforceTypeArguments, Engines, Namespace, SubstTypesContext, TypeId, TypeInfo, }; @@ -252,7 +252,7 @@ pub fn resolve_qualified_call_path( let type_decl = resolve_call_path( handler, engines, - namespace, + namespace.root(), mod_path, &qualified_call_path.clone().to_call_path(handler)?, self_type, @@ -301,7 +301,7 @@ pub fn resolve_qualified_call_path( resolve_call_path( handler, engines, - namespace, + namespace.root(), mod_path, &qualified_call_path.call_path, self_type, @@ -321,7 +321,7 @@ pub fn resolve_qualified_call_path( pub fn resolve_call_path( handler: &Handler, engines: &Engines, - namespace: &Namespace, + root: &Root, mod_path: &ModulePath, call_path: &CallPath, self_type: Option, @@ -336,7 +336,7 @@ pub fn resolve_call_path( let (decl, mod_path) = resolve_symbol_and_mod_path( handler, engines, - namespace.root_module(), + &root.module, &symbol_path, &call_path.suffix, self_type, @@ -359,7 +359,7 @@ pub fn resolve_call_path( // check the visibility of the call path elements // we don't check the first prefix because direct children are always accessible for prefix in iter_prefixes(&call_path.prefixes).skip(1) { - let module = namespace.lookup_submodule_from_absolute_path(handler, engines, prefix)?; + let module = root.module.lookup_submodule(handler, engines, prefix)?; if module.visibility().is_private() { let prefix_last = prefix[prefix.len() - 1].clone(); handler.emit_err(CompileError::ImportPrivateModule { diff --git a/sway-core/src/type_system/ast_elements/binding.rs b/sway-core/src/type_system/ast_elements/binding.rs index 9d88b0424ce..da62d0f61ac 100644 --- a/sway-core/src/type_system/ast_elements/binding.rs +++ b/sway-core/src/type_system/ast_elements/binding.rs @@ -220,7 +220,8 @@ impl TypeBinding> { // find the module that the symbol is in let type_info_prefix = ctx.namespace().prepend_module_path(&self.inner.prefixes); ctx.namespace() - .lookup_submodule_from_absolute_path(handler, engines, &type_info_prefix)?; + .root_module() + .lookup_submodule(handler, engines, &type_info_prefix)?; // create the type info object let type_info = type_info.apply_type_arguments(