Skip to content

Commit

Permalink
Fix importing a stable resource as unstable (#2053)
Browse files Browse the repository at this point in the history
This fixes a regression from #2046 identified in #1995
  • Loading branch information
alexcrichton authored Feb 14, 2025
1 parent 03876cb commit d9680fe
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/wit-parser/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2885,7 +2885,13 @@ impl Remap {
self.process_foreign_types(unresolved, pkgid, resolve)?;

for (id, span) in unresolved.required_resource_types.iter() {
let mut id = self.map_type(*id, Some(*span))?;
// Note that errors are ignored here because an error represents a
// type that has been configured away. If a type is configured away
// then any future use of it will generate an error so there's no
// need to validate that it's a resource here.
let Ok(mut id) = self.map_type(*id, Some(*span)) else {
continue;
};
loop {
match resolve.types[id].kind {
TypeDefKind::Type(Type::Id(i)) => id = i,
Expand Down
17 changes: 17 additions & 0 deletions crates/wit-parser/tests/ui/unstable-resource.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package a:b@0.1.0;

interface foo {
@unstable(feature = inactive)
use wasi:io/error@0.1.0.{error};

@unstable(feature = inactive)
x: func(y: borrow<error>);
}

package wasi:io@0.1.0 {
interface error {
resource error;
}
}


44 changes: 44 additions & 0 deletions crates/wit-parser/tests/ui/unstable-resource.wit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"worlds": [],
"interfaces": [
{
"name": "error",
"types": {
"error": 0
},
"functions": {},
"package": 0
},
{
"name": "foo",
"types": {},
"functions": {},
"package": 1
}
],
"types": [
{
"name": "error",
"kind": "resource",
"owner": {
"interface": 0
}
}
],
"packages": [
{
"name": "wasi:[email protected]",
"interfaces": {
"error": 0
},
"worlds": {}
},
{
"name": "a:[email protected]",
"interfaces": {
"foo": 1
},
"worlds": {}
}
]
}

0 comments on commit d9680fe

Please sign in to comment.