diff --git a/crates/wit-parser/src/resolve/error.rs b/crates/wit-parser/src/resolve/error.rs index ff7407c454..526aa9887e 100644 --- a/crates/wit-parser/src/resolve/error.rs +++ b/crates/wit-parser/src/resolve/error.rs @@ -11,6 +11,10 @@ use crate::{PackageName, SourceMap, Span, Stability}; /// Convenience alias for a `Result` whose error type is [`ResolveError`]. pub type ResolveResult = Result; +// 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)] @@ -21,6 +25,20 @@ pub enum ResolveErrorKind { requested: PackageName, known: Vec, }, + + /// 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 }, @@ -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, .. } @@ -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", diff --git a/crates/wit-parser/src/resolve/mod.rs b/crates/wit-parser/src/resolve/mod.rs index 8297d3f7c2..388e2767b7 100644 --- a/crates/wit-parser/src/resolve/mod.rs +++ b/crates/wit-parser/src/resolve/mod.rs @@ -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. @@ -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)); @@ -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)); diff --git a/crates/wit-parser/tests/ui/parse-fail/bad-pkg2.wit.result b/crates/wit-parser/tests/ui/parse-fail/bad-pkg2.wit.result index 235a806d21..ca12daae49 100644 --- a/crates/wit-parser/tests/ui/parse-fail/bad-pkg2.wit.result +++ b/crates/wit-parser/tests/ui/parse-fail/bad-pkg2.wit.result @@ -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.{}; diff --git a/crates/wit-parser/tests/ui/parse-fail/bad-pkg3.wit.result b/crates/wit-parser/tests/ui/parse-fail/bad-pkg3.wit.result index d3d2102d7b..59d9e2e14e 100644 --- a/crates/wit-parser/tests/ui/parse-fail/bad-pkg3.wit.result +++ b/crates/wit-parser/tests/ui/parse-fail/bad-pkg3.wit.result @@ -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.{}; diff --git a/crates/wit-parser/tests/ui/parse-fail/include-foreign.wit.result b/crates/wit-parser/tests/ui/parse-fail/include-foreign.wit.result index 495d331006..6bd7b22433 100644 --- a/crates/wit-parser/tests/ui/parse-fail/include-foreign.wit.result +++ b/crates/wit-parser/tests/ui/parse-fail/include-foreign.wit.result @@ -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; diff --git a/crates/wit-parser/tests/ui/parse-fail/non-existence-world-include.wit.result b/crates/wit-parser/tests/ui/parse-fail/non-existence-world-include.wit.result index 545cb1aca7..6d4d362305 100644 --- a/crates/wit-parser/tests/ui/parse-fail/non-existence-world-include.wit.result +++ b/crates/wit-parser/tests/ui/parse-fail/non-existence-world-include.wit.result @@ -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; diff --git a/crates/wit-parser/tests/ui/parse-fail/use-world.wit.result b/crates/wit-parser/tests/ui/parse-fail/use-world.wit.result index a85972579b..975def98c5 100644 --- a/crates/wit-parser/tests/ui/parse-fail/use-world.wit.result +++ b/crates/wit-parser/tests/ui/parse-fail/use-world.wit.result @@ -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; diff --git a/tests/cli/component-model/custom-page-sizes.wast b/tests/cli/component-model/custom-page-sizes.wast index 28c56f4d87..d56cb84858 100644 --- a/tests/cli/component-model/custom-page-sizes.wast +++ b/tests/cli/component-model/custom-page-sizes.wast @@ -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))))