Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions crates/wit-parser/src/resolve/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use crate::{PackageName, SourceMap, Span, Stability};
/// Convenience alias for a `Result` whose error type is [`ResolveError`].
pub type ResolveResult<T, E = ResolveError> = Result<T, E>;

// temporary alias since most errors do not return `Ident`
pub(crate) type WorldName = String;
pub(crate) type InterfaceName = String;

/// The category of error that occurred while resolving a WIT package.
#[non_exhaustive]
#[derive(Debug, PartialEq, Eq)]
Expand All @@ -21,6 +25,20 @@ pub enum ResolveErrorKind {
requested: PackageName,
known: Vec<PackageName>,
},

/// A referenced world could not be found for the provided package
WorldNotFound {
span: Span,
requested: WorldName,
package: PackageName,
},

/// A referenced interface could not be found for the provided package
InterfaceNotFound {
span: Span,
requested: InterfaceName,
package: PackageName,
},
/// An interface has a transitive dependency that creates an incompatible
/// import relationship.
InvalidTransitiveDependency { span: Span, name: String },
Expand Down Expand Up @@ -53,6 +71,8 @@ impl ResolveErrorKind {
pub fn span(&self) -> Span {
match self {
ResolveErrorKind::PackageNotFound { span, .. }
| ResolveErrorKind::WorldNotFound { span, .. }
| ResolveErrorKind::InterfaceNotFound { span, .. }
| ResolveErrorKind::InvalidTransitiveDependency { span, .. }
| ResolveErrorKind::PackageCycle { span, .. }
| ResolveErrorKind::ItemShadowing { span, .. }
Expand All @@ -79,6 +99,15 @@ impl fmt::Display for ResolveErrorKind {
Ok(())
}
}
ResolveErrorKind::WorldNotFound {
requested, package, ..
} => write!(f, "world '{requested}' not found in package '{package}'"),
ResolveErrorKind::InterfaceNotFound {
requested, package, ..
} => write!(
f,
"interface '{requested}' not found in package '{package}'"
),
ResolveErrorKind::InvalidTransitiveDependency { name, .. } => write!(
f,
"interface `{name}` transitively depends on an interface in incompatible ways",
Expand Down
14 changes: 11 additions & 3 deletions crates/wit-parser/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,7 @@ impl Resolve {
// never being importable-from it means that mutations to `CloneMaps`
// are discarded when named interfaces are cloned. The trick here
// happens where this unconditionally preserves all modifications to
// `CloneMaps` for `WorldKey::Interface` clones. Behaivor then "falls
// `CloneMaps` for `WorldKey::Interface` clones. Behavior then "falls
// out" where references to cloned interfaces are naturally rewritten.
//
// This all falls down, however, if an import is cloned and recorded.
Expand Down Expand Up @@ -3782,7 +3782,11 @@ impl Remap {
}

let iface_id = pkg.interfaces.get(interface).copied().ok_or_else(|| {
ResolveError::new_semantic(iface_span, "interface not found in package")
ResolveError::from(ResolveErrorKind::InterfaceNotFound {
span: iface_span,
requested: interface.to_string(),
package: pkg.name.clone(),
})
})?;
assert_eq!(self.interfaces.len(), unresolved_iface_id.index());
self.interfaces.push(Some(iface_id));
Expand Down Expand Up @@ -3840,7 +3844,11 @@ impl Remap {
}

let world_id = pkg.worlds.get(world).copied().ok_or_else(|| {
ResolveError::new_semantic(world_span, "world not found in package")
ResolveError::from(ResolveErrorKind::WorldNotFound {
span: world_span,
requested: world.to_string(),
package: pkg.name.clone(),
})
})?;
assert_eq!(self.worlds.len(), unresolved_world_id.index());
self.worlds.push(Some(world_id));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg2]: interface not found in package
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg2]: interface 'nonexistent' not found in package 'foo:bar'
--> tests/ui/parse-fail/bad-pkg2/root.wit:4:15
|
4 | use foo:bar/nonexistent.{};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg3]: interface not found in package
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg3]: interface 'baz' not found in package 'foo:bar'
--> tests/ui/parse-fail/bad-pkg3/root.wit:4:15
|
4 | use foo:bar/baz.{};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/include-foreign]: world not found in package
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/include-foreign]: world 'bar' not found in package 'foo:bar'
--> tests/ui/parse-fail/include-foreign/root.wit:4:19
|
4 | include foo:bar/bar;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/non-existence-world-include]: world not found in package
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/non-existence-world-include]: world 'non-existence' not found in package 'foo:baz'
--> tests/ui/parse-fail/non-existence-world-include/root.wit:4:19
|
4 | include foo:baz/non-existence;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/use-world]: interface not found in package
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/use-world]: interface 'bar' not found in package 'foo:baz'
--> tests/ui/parse-fail/use-world/root.wit:3:13
|
3 | use foo:baz/bar;
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/component-model/custom-page-sizes.wast
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(core func (canon lower (func $f) (memory (core memory $i "m"))))
)

;; subtyping works with explict page sizes
;; subtyping works with explicit page sizes
(component
(core module $a (memory (export "m") 1 (pagesize 65536)))
(core module $b (import "a" "m" (memory 1 (pagesize 65536))))
Expand Down
Loading