From e86400e643897a83004058af4df47a4f928d0ba8 Mon Sep 17 00:00:00 2001 From: Yi LIU Date: Thu, 12 Feb 2026 19:48:53 +0800 Subject: [PATCH 1/2] Fix panic in remove_node for Definition nodes Definition nodes store their name in the `export` field, not the `name` field (which is None). The log::debug! in remove_node incorrectly used `node.name.as_ref().unwrap()`, which panics for Definition nodes. Changed to `node.export.as_ref().unwrap()`, matching the pattern used elsewhere (e.g., the Display impl at line 1324). Added a unit test that verifies remove_node works correctly for type definition nodes. --- crates/wac-graph/src/graph.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/wac-graph/src/graph.rs b/crates/wac-graph/src/graph.rs index 28ab8dc..a9cbfe3 100644 --- a/crates/wac-graph/src/graph.rs +++ b/crates/wac-graph/src/graph.rs @@ -1029,7 +1029,7 @@ impl CompositionGraph { if let NodeKind::Definition = node.kind { log::debug!( "removing type definition `{name}`", - name = node.name.as_ref().unwrap() + name = node.export.as_ref().unwrap() ); let removed = self.defined.remove(&node.item_kind.ty()); assert!(removed.is_some()); @@ -1959,4 +1959,22 @@ mod test { UnexportError::MustExportDefinition )); } + + #[test] + fn it_can_remove_a_type_definition() { + let mut graph = CompositionGraph::new(); + let ty_id = graph + .types_mut() + .add_defined_type(DefinedType::Alias(ValueType::Primitive(PrimitiveType::S32))); + let node_id = graph + .define_type("foo", Type::Value(ValueType::Defined(ty_id))) + .unwrap(); + + // Definition nodes store their name in `export`, not `name`. + // Removing a definition node should not panic. + graph.remove_node(node_id); + + // Verify the definition and export were cleaned up + assert!(graph.get_export("foo").is_none()); + } } From d9233d7cb3d55c899aff84fed5b4c70543a045a8 Mon Sep 17 00:00:00 2001 From: Brian Hardock Date: Tue, 17 Feb 2026 13:34:21 -0700 Subject: [PATCH 2/2] Fix fmt Signed-off-by: Brian Hardock --- crates/wac-graph/src/graph.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wac-graph/src/graph.rs b/crates/wac-graph/src/graph.rs index 04d04e4..7948e5b 100644 --- a/crates/wac-graph/src/graph.rs +++ b/crates/wac-graph/src/graph.rs @@ -1986,7 +1986,7 @@ mod test { // Verify the definition and export were cleaned up assert!(graph.get_export("foo").is_none()); } - + #[test] fn it_cleans_up_exports_on_unregister_package() { let mut graph = CompositionGraph::new(); let bytes = wat::parse_str(