Skip to content

Commit 6072bc3

Browse files
committed
Code review feedback.
1 parent f88d693 commit 6072bc3

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

crates/wac-types/src/aggregator.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ impl TypeAggregator {
5757
kind: ItemKind,
5858
checker: &mut SubtypeChecker,
5959
) -> Result<Self> {
60+
// First check if this import has already been remapped into our
61+
// types collection.
62+
// If it has already been remapped, do a merge; otherwise, remap it.
6063
if let Some(existing) = self.names.get(name).copied() {
6164
self.merge_item_kind(existing, types, kind, checker)?;
6265
return Ok(self);
@@ -160,7 +163,7 @@ impl TypeAggregator {
160163
) -> Result<()> {
161164
let source = &types[id];
162165
for (name, used) in &source.uses {
163-
let source_interface = types[used.interface]
166+
let used_interface = types[used.interface]
164167
.id
165168
.as_ref()
166169
.context("used type has no interface identifier")?;
@@ -173,8 +176,8 @@ impl TypeAggregator {
173176
.context("used type has no interface identifier")?;
174177

175178
// The interface names must match
176-
if existing_interface != source_interface {
177-
bail!("cannot merge used type `{name}` as it is expected to be from interface `{existing_interface}` but it is from interface `{source_interface}`");
179+
if existing_interface != used_interface {
180+
bail!("cannot merge used type `{name}` as it is expected to be from interface `{existing_interface}` but it is from interface `{used_interface}`");
178181
}
179182

180183
// The types must be exported with the same name
@@ -193,14 +196,13 @@ impl TypeAggregator {
193196
);
194197
}
195198
None => {
196-
let prev = self.types[existing].uses.insert(
199+
self.types[existing].uses.insert(
197200
name.clone(),
198201
UsedType {
199202
interface: remapped,
200203
name: used.name.clone(),
201204
},
202205
);
203-
assert!(prev.is_none());
204206
}
205207
}
206208
}
@@ -298,7 +300,7 @@ impl TypeAggregator {
298300
) -> Result<()> {
299301
let source = &types[id];
300302
for (name, used) in &source.uses {
301-
let source_interface = types[used.interface]
303+
let used_interface = types[used.interface]
302304
.id
303305
.as_ref()
304306
.context("used type has no interface identifier")?;
@@ -311,8 +313,8 @@ impl TypeAggregator {
311313
.context("used type has no interface identifier")?;
312314

313315
// The interface names must match
314-
if existing_interface != source_interface {
315-
bail!("cannot merge used type `{name}` as it is expected to be from interface `{existing_interface}` but it is from interface `{source_interface}`");
316+
if existing_interface != used_interface {
317+
bail!("cannot merge used type `{name}` as it is expected to be from interface `{existing_interface}` but it is from interface `{used_interface}`");
316318
}
317319

318320
// The types must be exported with the same name

0 commit comments

Comments
 (0)