From 0244ef21fbfc91976e6b04e6bbed3c839797fad2 Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Wed, 9 Oct 2024 09:29:02 +0100 Subject: [PATCH] Fixes double call of get_items_for_type. --- .../semantic_analysis/type_check_context.rs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/sway-core/src/semantic_analysis/type_check_context.rs b/sway-core/src/semantic_analysis/type_check_context.rs index fb68d4e6ca6..b42fd0b13ff 100644 --- a/sway-core/src/semantic_analysis/type_check_context.rs +++ b/sway-core/src/semantic_analysis/type_check_context.rs @@ -719,14 +719,6 @@ impl<'a> TypeCheckContext<'a> { return Err(*err); } - // grab the local module - let local_module = self - .namespace() - .require_module_from_absolute_path(handler, &self.namespace().current_mod_path)?; - - // grab the local items from the local module - let local_items = local_module.get_items_for_type(self.engines, type_id); - // resolve the type let type_id = resolve_type( handler, @@ -743,16 +735,26 @@ impl<'a> TypeCheckContext<'a> { ) .unwrap_or_else(|err| type_engine.id_of_error_recovery(err)); - // grab the module where the type itself is declared - let type_module = self + // grab the local module + let local_module = self .namespace() - .require_module_from_absolute_path(handler, &item_prefix.to_vec())?; + .require_module_from_absolute_path(handler, &self.namespace().current_mod_path)?; - // grab the items from where the type is declared - let mut type_items = type_module.get_items_for_type(self.engines, type_id); + // grab the local items from the local module + let local_items = local_module.get_items_for_type(self.engines, type_id); let mut items = local_items; - items.append(&mut type_items); + if item_prefix.to_vec() != self.namespace().current_mod_path { + // grab the module where the type itself is declared + let type_module = self + .namespace() + .require_module_from_absolute_path(handler, &item_prefix.to_vec())?; + + // grab the items from where the type is declared + let mut type_items = type_module.get_items_for_type(self.engines, type_id); + + items.append(&mut type_items); + } let mut matching_item_decl_refs: Vec = vec![];