@@ -661,22 +661,10 @@ impl<H: CompilerHost> Resolver<'_, H> {
661661 module_source,
662662 ..
663663 } => {
664- // Use the flat struct_fields map first. When there's a name collision
665- // (the entry is from a different module), re-resolve fields from the
666- // source module to get the correct struct definition.
667- if let Some ( struct_info) = self . struct_fields . get ( & name) {
668- if struct_info. module_source == module_source {
669- for ( index, ( fname, ftype, _) ) in struct_info. fields . iter ( ) . enumerate ( ) {
670- if fname == field_name {
671- return ( index as u32 , * ftype) ;
672- }
673- }
674- } else {
675- // Name collision: re-resolve field type from the loaded module
676- if let Some ( ftype) =
677- self . resolve_field_in_source_module ( & name, field_name, & module_source)
678- {
679- return ftype;
664+ if let Some ( struct_info) = self . lookup_struct_fields ( & name, & module_source) {
665+ for ( index, ( fname, ftype, _) ) in struct_info. fields . iter ( ) . enumerate ( ) {
666+ if fname == field_name {
667+ return ( index as u32 , * ftype) ;
680668 }
681669 }
682670 }
@@ -715,7 +703,7 @@ impl<H: CompilerHost> Resolver<'_, H> {
715703 return ( 0 , TypeTable :: UNKNOWN ) ;
716704 }
717705 // Clone fields to avoid borrow issues
718- let fields_clone = self . struct_fields . get ( & name) . cloned ( ) ;
706+ let fields_clone = self . lookup_struct_fields ( & name, & module_source ) . cloned ( ) ;
719707 if let Some ( struct_info) = fields_clone {
720708 for ( index, ( fname, ftype, _) ) in struct_info. fields . iter ( ) . enumerate ( ) {
721709 if fname == field_name {
@@ -731,64 +719,6 @@ impl<H: CompilerHost> Resolver<'_, H> {
731719 ( 0 , TypeTable :: UNKNOWN )
732720 }
733721
734- /// Resolve a struct field type from the source module where the struct is defined.
735- /// Used when the flat `struct_fields` map has a name collision (two modules define
736- /// a struct with the same name). This re-resolves the field type in the source
737- /// module's type context to get the correct result.
738- pub ( super ) fn resolve_field_in_source_module (
739- & mut self ,
740- struct_name : & str ,
741- field_name : & str ,
742- module_source : & ModuleSource ,
743- ) -> Option < ( u32 , TypeId ) > {
744- // Pre-populate module type maps cache before borrowing loaded_modules
745- self . ensure_module_maps_cached ( module_source) ;
746-
747- let loaded_module = self . loaded_modules . get ( module_source) ?;
748- // Find the struct declaration in the loaded module
749- let struct_decl = loaded_module. items . iter ( ) . find_map ( |item| {
750- if let Item :: Struct ( s) = item
751- && s. name == struct_name
752- {
753- Some ( s)
754- } else {
755- None
756- }
757- } ) ?;
758-
759- // Swap to source module's type context using cached maps (O(1))
760- let mut cached = self
761- . module_type_maps_cache
762- . shift_remove ( module_source)
763- . expect ( "cache populated by ensure_module_maps_cached" ) ;
764- std:: mem:: swap ( & mut self . struct_fields , & mut cached. struct_fields ) ;
765- std:: mem:: swap ( & mut self . variant_cases , & mut cached. variant_cases ) ;
766- std:: mem:: swap ( & mut self . enum_cases , & mut cached. enum_cases ) ;
767- std:: mem:: swap ( & mut self . flags_cases , & mut cached. flags_cases ) ;
768- std:: mem:: swap ( & mut self . newtypes , & mut cached. newtypes ) ;
769- std:: mem:: swap ( & mut self . resource_types , & mut cached. resource_types ) ;
770-
771- // Find and resolve the field type
772- let result = struct_decl
773- . fields
774- . iter ( )
775- . enumerate ( )
776- . find ( |( _, f) | f. name == field_name)
777- . map ( |( index, f) | ( index as u32 , self . resolve_type ( & f. ty ) ) ) ;
778-
779- // Restore type maps and re-cache
780- std:: mem:: swap ( & mut self . struct_fields , & mut cached. struct_fields ) ;
781- std:: mem:: swap ( & mut self . variant_cases , & mut cached. variant_cases ) ;
782- std:: mem:: swap ( & mut self . enum_cases , & mut cached. enum_cases ) ;
783- std:: mem:: swap ( & mut self . flags_cases , & mut cached. flags_cases ) ;
784- std:: mem:: swap ( & mut self . newtypes , & mut cached. newtypes ) ;
785- std:: mem:: swap ( & mut self . resource_types , & mut cached. resource_types ) ;
786- self . module_type_maps_cache
787- . insert ( module_source. clone ( ) , cached) ;
788-
789- result
790- }
791-
792722 /// Check if a struct field is accessible from the current module.
793723 /// Non-pub fields are private to the module that defines them.
794724 fn check_field_visibility ( & mut self , struct_type : TypeId , field_name : & str , span : Span ) {
@@ -821,7 +751,7 @@ impl<H: CompilerHost> Resolver<'_, H> {
821751 }
822752
823753 // Look up field visibility
824- if let Some ( struct_info) = self . struct_fields . get ( & struct_name) {
754+ if let Some ( struct_info) = self . lookup_struct_fields ( & struct_name, & module_source ) {
825755 for ( fname, _, is_pub) in & struct_info. fields {
826756 if fname == field_name && !is_pub {
827757 let _ = self . logger . error ( TypeError :: TypeMismatch {
0 commit comments