Skip to content

Commit 85e0651

Browse files
committed
Don't assume item is the top level item from the node
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
1 parent 3fb7ef4 commit 85e0651

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

crates/wac-graph/src/graph.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,8 +1261,10 @@ impl CompositionGraph {
12611261
}
12621262

12631263
/// Yields an iterator over the resolved imports (both implicit and explicit) of the graph.
1264-
pub fn imports(&self) -> impl Iterator<Item = (&str, NodeId)> {
1265-
let mut imports = HashMap::new();
1264+
///
1265+
/// The iterator returns the name, the `ItemKind`, and an optional node id for explicit imports.
1266+
pub fn imports(&self) -> impl Iterator<Item = (&str, ItemKind, Option<NodeId>)> {
1267+
let mut imports = Vec::new();
12661268
for index in self.graph.node_indices() {
12671269
let node = &self.graph[index];
12681270
if !matches!(node.kind, NodeKind::Instantiation(_)) {
@@ -1279,15 +1281,15 @@ impl CompositionGraph {
12791281
.filter(|(i, _)| !node.is_arg_satisfied(*i));
12801282

12811283
// Go through the unsatisfied arguments and import them
1282-
for (_, (name, _)) in unsatisfied_args {
1283-
imports.insert(name.as_str(), NodeId(index));
1284+
for (_, (name, item_kind)) in unsatisfied_args {
1285+
imports.push((name.as_str(), *item_kind, None));
12841286
}
12851287
}
12861288

12871289
for n in self.node_ids() {
12881290
let node = &self.graph[n.0];
12891291
if let NodeKind::Import(name) = &node.kind {
1290-
imports.insert(name.as_str(), n);
1292+
imports.push((name.as_str(), node.item_kind, Some(n)));
12911293
}
12921294
}
12931295
imports.into_iter()

crates/wac-parser/src/resolution.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ pub enum Error {
635635
world: String,
636636
/// The span where the error occurred.
637637
#[label(primary, "mismatched type for {kind} `{name}`")]
638-
span: SourceSpan,
638+
span: Option<SourceSpan>,
639639
/// The source of the error.
640640
#[source]
641641
source: anyhow::Error,
@@ -2717,28 +2717,28 @@ impl<'a> AstResolver<'a> {
27172717

27182718
// The output is allowed to import a subset of the world's imports
27192719
checker.invert();
2720-
for (name, import) in state.graph.imports() {
2720+
for (name, item_kind, import_node) in state.graph.imports() {
27212721
let expected = world
27222722
.imports
27232723
.get(name)
27242724
.ok_or_else(|| Error::ImportNotInTarget {
27252725
name: name.to_owned(),
27262726
world: path.string.to_owned(),
2727-
span: state.import_spans.get(&import).copied(),
2727+
span: import_node.map(|n| state.import_spans[&n]),
27282728
})?;
27292729

27302730
checker
27312731
.is_subtype(
27322732
expected.promote(),
27332733
state.graph.types(),
2734-
state.graph[import].item_kind(),
2734+
item_kind,
27352735
state.graph.types(),
27362736
)
27372737
.map_err(|e| Error::TargetMismatch {
27382738
kind: ExternKind::Import,
27392739
name: name.to_owned(),
27402740
world: path.string.to_owned(),
2741-
span: state.import_spans[&import],
2741+
span: import_node.map(|n| state.import_spans[&n]),
27422742
source: e,
27432743
})?;
27442744
}
@@ -2769,7 +2769,7 @@ impl<'a> AstResolver<'a> {
27692769
kind: ExternKind::Export,
27702770
name: name.clone(),
27712771
world: path.string.to_owned(),
2772-
span: state.export_spans[&export],
2772+
span: state.export_spans.get(&export).copied(),
27732773
source: e,
27742774
})?;
27752775
}

0 commit comments

Comments
 (0)