Skip to content

Commit 5b8c47a

Browse files
committed
Fix remapping of used types.
This commit fixes the remapping of used types that occurs when merging implicitly imported interfaces.
1 parent f55ca86 commit 5b8c47a

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

  • crates/wac-parser/src/resolution

crates/wac-parser/src/resolution/ast.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,19 +1950,31 @@ impl<'a> AstResolver<'a> {
19501950
uses: IndexMap<InterfaceId, IndexSet<usize>>,
19511951
) -> IndexMap<InterfaceId, IndexSet<usize>> {
19521952
// Now update all the interface ids in the usings
1953-
uses.into_iter()
1954-
.map(|(dep, exports)| {
1955-
let import =
1956-
&state.imports[self.definitions.interfaces[dep].id.as_deref().unwrap()];
1957-
match &state.current.items[import.item] {
1958-
super::Item::Import(super::Import {
1959-
kind: ItemKind::Instance(id),
1960-
..
1961-
}) => (*id, exports),
1962-
_ => unreachable!(),
1953+
let mut remapped: IndexMap<InterfaceId, IndexSet<usize>> =
1954+
IndexMap::with_capacity(uses.len());
1955+
for (old_id, exports) in uses {
1956+
let old = &self.definitions.interfaces[old_id];
1957+
let import = &state.imports[old.id.as_deref().unwrap()];
1958+
match &state.current.items[import.item] {
1959+
super::Item::Import(super::Import {
1960+
kind: ItemKind::Instance(new_id),
1961+
..
1962+
}) => {
1963+
let new = &self.definitions.interfaces[*new_id];
1964+
remapped
1965+
.entry(*new_id)
1966+
.or_default()
1967+
.extend(exports.into_iter().map(|old_index| {
1968+
new.exports
1969+
.get_index_of(old.exports.get_index(old_index).unwrap().0)
1970+
.unwrap()
1971+
}));
19631972
}
1964-
})
1965-
.collect()
1973+
_ => unreachable!(),
1974+
}
1975+
}
1976+
1977+
remapped
19661978
}
19671979

19681980
fn named_instantiation_arg(

0 commit comments

Comments
 (0)