@@ -23,7 +23,7 @@ pub struct TypeAggregator {
2323 /// The aggregated types collection.
2424 types : Types ,
2525 /// The map from import name to aggregated item kind.
26- names : IndexMap < String , ItemKind > ,
26+ imports : IndexMap < String , ItemKind > ,
2727 /// A map from foreign type to remapped local type.
2828 remapped : HashMap < Type , Type > ,
2929 /// A map of interface names to remapped interface id.
@@ -41,9 +41,9 @@ impl TypeAggregator {
4141 & self . types
4242 }
4343
44- /// Iterates the named types in the aggregator.
45- pub fn iter ( & self ) -> impl Iterator < Item = ( & str , ItemKind ) > {
46- self . names . iter ( ) . map ( |( n, k) | ( n. as_str ( ) , * k) )
44+ /// Iterates the imported types in the aggregator.
45+ pub fn imports ( & self ) -> impl Iterator < Item = ( & str , ItemKind ) > {
46+ self . imports . iter ( ) . map ( |( n, k) | ( n. as_str ( ) , * k) )
4747 }
4848
4949 /// Aggregates a item kind from a specified type collection using the given
@@ -60,13 +60,13 @@ impl TypeAggregator {
6060 // First check if this import has already been remapped into our
6161 // types collection.
6262 // If it has already been remapped, do a merge; otherwise, remap it.
63- if let Some ( existing) = self . names . get ( name) . copied ( ) {
63+ if let Some ( existing) = self . imports . get ( name) . copied ( ) {
6464 self . merge_item_kind ( existing, types, kind, checker) ?;
6565 return Ok ( self ) ;
6666 }
6767
68- let ty = self . remap_item_kind ( types, kind, checker) ?;
69- let prev = self . names . insert ( name. to_string ( ) , ty ) ;
68+ let remapped = self . remap_item_kind ( types, kind, checker) ?;
69+ let prev = self . imports . insert ( name. to_string ( ) , remapped ) ;
7070 assert ! ( prev. is_none( ) ) ;
7171 Ok ( self )
7272 }
@@ -549,11 +549,27 @@ impl TypeAggregator {
549549 alias : resource
550550 . alias
551551 . map ( |a| -> Result < _ > {
552+ let owner = a
553+ . owner
554+ . map ( |id| {
555+ // There's no need to merge the interface here as
556+ // merging is done as part of the interface remapping
557+ self . remap_interface ( types, id, checker)
558+ } )
559+ . transpose ( ) ?;
560+ // If there is an owning interface, ensure it is imported
561+ if let Some ( owner) = owner {
562+ let name = self . types ( ) [ owner]
563+ . id
564+ . as_deref ( )
565+ . expect ( "interface has no id" ) ;
566+ if !self . imports . contains_key ( name) {
567+ self . imports
568+ . insert ( name. to_owned ( ) , ItemKind :: Instance ( owner) ) ;
569+ }
570+ }
552571 Ok ( ResourceAlias {
553- owner : a
554- . owner
555- . map ( |id| self . remap_interface ( types, id, checker) )
556- . transpose ( ) ?,
572+ owner,
557573 source : self . remap_resource ( types, a. source , checker) ?,
558574 } )
559575 } )
0 commit comments