Skip to content

Commit b7123c5

Browse files
Fixes double call of get_items_for_type. (#6626)
## Description ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
1 parent 1270bfa commit b7123c5

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

sway-core/src/semantic_analysis/type_check_context.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -719,14 +719,6 @@ impl<'a> TypeCheckContext<'a> {
719719
return Err(*err);
720720
}
721721

722-
// grab the local module
723-
let local_module = self
724-
.namespace()
725-
.require_module_from_absolute_path(handler, &self.namespace().current_mod_path)?;
726-
727-
// grab the local items from the local module
728-
let local_items = local_module.get_items_for_type(self.engines, type_id);
729-
730722
// resolve the type
731723
let type_id = resolve_type(
732724
handler,
@@ -743,16 +735,26 @@ impl<'a> TypeCheckContext<'a> {
743735
)
744736
.unwrap_or_else(|err| type_engine.id_of_error_recovery(err));
745737

746-
// grab the module where the type itself is declared
747-
let type_module = self
738+
// grab the local module
739+
let local_module = self
748740
.namespace()
749-
.require_module_from_absolute_path(handler, &item_prefix.to_vec())?;
741+
.require_module_from_absolute_path(handler, &self.namespace().current_mod_path)?;
750742

751-
// grab the items from where the type is declared
752-
let mut type_items = type_module.get_items_for_type(self.engines, type_id);
743+
// grab the local items from the local module
744+
let local_items = local_module.get_items_for_type(self.engines, type_id);
753745

754746
let mut items = local_items;
755-
items.append(&mut type_items);
747+
if item_prefix.to_vec() != self.namespace().current_mod_path {
748+
// grab the module where the type itself is declared
749+
let type_module = self
750+
.namespace()
751+
.require_module_from_absolute_path(handler, &item_prefix.to_vec())?;
752+
753+
// grab the items from where the type is declared
754+
let mut type_items = type_module.get_items_for_type(self.engines, type_id);
755+
756+
items.append(&mut type_items);
757+
}
756758

757759
let mut matching_item_decl_refs: Vec<ty::TyTraitItem> = vec![];
758760

0 commit comments

Comments
 (0)