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
2 changes: 1 addition & 1 deletion crates/wac-parser/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> Parse<'a> for Expr<'a> {

let start = primary.span();
let len = postfix.last().map_or(start.len(), |p| {
start.offset() + p.span().offset() + p.span().len()
p.span().offset() + p.span().len() - start.offset()
});

Ok(Self {
Expand Down
15 changes: 9 additions & 6 deletions crates/wac-parser/src/resolution/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,8 +1534,8 @@ impl<'a> AstResolver<'a> {
hash_map::Entry::Occupied(e) => Ok(*e.get()),
hash_map::Entry::Vacant(e) => {
log::debug!("resolving package `{name}`");
let bytes = match self.packages.remove(&PackageKey { name, version }) {
Some(bytes) => bytes,
let bytes = match self.packages.get(&PackageKey { name, version }) {
Some(bytes) => bytes.clone(),
None => {
return Err(Error::UnknownPackage {
name: name.to_string(),
Expand Down Expand Up @@ -1788,7 +1788,7 @@ impl<'a> AstResolver<'a> {
);

SubtypeChecker::new(&self.definitions, &state.packages)
.is_subtype(*expected, state.current.items[*item].kind())
.is_subtype(state.current.items[*item].kind(), *expected)
.map_err(|e| Error::MismatchedInstantiationArg {
name: name.clone(),
span: *span,
Expand Down Expand Up @@ -1965,10 +1965,10 @@ impl<'a> AstResolver<'a> {

match (
checker
.is_subtype(*target_kind, *source_kind)
.is_subtype(*source_kind, *target_kind)
.with_context(|| format!("mismatched type for export `{name}`")),
checker
.is_subtype(*source_kind, *target_kind)
.is_subtype(*target_kind, *source_kind)
.with_context(|| format!("mismatched type for export `{name}`")),
) {
(Ok(_), Ok(_)) => {
Expand Down Expand Up @@ -2273,6 +2273,7 @@ impl<'a> AstResolver<'a> {
let mut checker = SubtypeChecker::new(&self.definitions, &state.packages);

// The output is allowed to import a subset of the world's imports
checker.invert();
for (name, import) in &state.imports {
let expected = world
.imports
Expand All @@ -2297,6 +2298,8 @@ impl<'a> AstResolver<'a> {
})?;
}

checker.revert();

// The output must export every export in the world
for (name, expected) in &world.exports {
let export = state
Expand All @@ -2311,8 +2314,8 @@ impl<'a> AstResolver<'a> {

checker
.is_subtype(
expected.promote(),
state.root_scope().items[export.item].kind(),
expected.promote(),
)
.map_err(|e| Error::TargetMismatch {
kind: ExternKind::Export,
Expand Down
Loading