Skip to content

Commit 812d78e

Browse files
committed
Error if wit file is found for package
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
1 parent b294ae0 commit 812d78e

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a> Parse<'a> for ImportType<'a> {
118118
}
119119
}
120120

121-
/// Represents a package path in the AST.
121+
/// AST representation of a path to an item such as a world in a package (e.g. `foo:bar/qux`).
122122
#[derive(Debug, Clone, Serialize)]
123123
#[serde(rename_all = "camelCase")]
124124
pub struct PackagePath<'a> {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ impl<'a> AstResolver<'a> {
184184
// If there's a target world in the directive, validate the composition
185185
// conforms to the target
186186
if let Some(path) = &self.document.directive.targets {
187+
log::debug!("validating composition targets world `{}`", path.string);
187188
let item = self.resolve_package_export(&mut state, path)?;
188189
match item {
189190
ItemKind::Type(Type::World(world)) => {
@@ -1563,6 +1564,7 @@ impl<'a> AstResolver<'a> {
15631564
state: &mut State<'a>,
15641565
path: &'a ast::PackagePath<'a>,
15651566
) -> ResolutionResult<ItemKind> {
1567+
log::debug!("resolving package export `{}`", path.string);
15661568
// Check for reference to local item
15671569
if path.name == self.document.directive.package.name {
15681570
return self.resolve_local_export(state, path);

crates/wac-resolver/src/fs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ impl FileSystemPackageResolver {
114114
);
115115

116116
continue;
117+
} else if path.extension().and_then(std::ffi::OsStr::to_str) == Some("wit") {
118+
return Err(Error::PackageResolutionFailure {
119+
name: key.name.to_string(),
120+
span: *span,
121+
source: anyhow!(
122+
"WIT packages must be directories, not files: `{path}`",
123+
path = path.display()
124+
),
125+
});
117126
}
118127

119128
if !path.is_file() {

0 commit comments

Comments
 (0)