Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
validate conflicting package names
Browse files Browse the repository at this point in the history
  • Loading branch information
noise64 committed Nov 14, 2024
1 parent a2789df commit aa2ae4c
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion wasm-rpc-stubgen/src/wit_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl ResolvedWitApplication {

resolved_app.add_components_from_app(&mut validation, app);

// TODO: validate conflicting package names
resolved_app.validate_package_names(&mut validation);

if !validation.has_any_errors() {
resolved_app.collect_component_deps();
Expand All @@ -201,6 +201,37 @@ impl ResolvedWitApplication {
validation.build(resolved_app)
}

fn validate_package_names(&self, validation: &mut ValidationBuilder) {
if self.package_to_component.len() != self.components.len() {
let mut package_names_to_component_names =
BTreeMap::<&PackageName, Vec<&ComponentName>>::new();
for (component_name, component) in &self.components {
package_names_to_component_names
.entry(&component.main_package_name)
.and_modify(|component_names| component_names.push(&component_name))
.or_insert_with(|| vec![&component_name]);
}

validation.add_errors(
package_names_to_component_names,
|(package_name, component_names)| {
(component_names.len() > 1).then(|| {
(
vec![
("package name", package_name.to_string()),
(
"component names",
component_names.iter().map(|s| s.as_str()).join(", "),
),
],
"Same package name is used for multiple components".to_string(),
)
})
},
);
}
}

fn add_resolved_component(
&mut self,
component_name: ComponentName,
Expand Down

0 comments on commit aa2ae4c

Please sign in to comment.