Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More cargo component new generator fixes #304

Merged
merged 1 commit into from
May 24, 2024
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
20 changes: 20 additions & 0 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ impl<'a> UnimplementedFunction<'a> {

fn is_exported_resource(&self, id: TypeId) -> bool {
let type_info = &self.resolve.types[id];
if let TypeOwner::World(_) = type_info.owner {
return false;
}
match type_info.kind {
TypeDefKind::Type(Type::Id(kind_id)) => {
let kind_type = &self.resolve.types[kind_id];
Expand Down Expand Up @@ -573,6 +576,23 @@ impl<'a> InterfaceGenerator<'a> {
}
}

// Add resources that did not have any methods
for (_, id) in interface.types.iter() {
let ty = &resolve.types[*id];
if ty.kind == TypeDefKind::Resource && !resources.contains_key(id) {
let name = ty.name.as_deref().expect("unnamed resource type");
let impl_name = names.reserve(name);
resources.insert(
*id,
Resource {
ty,
impl_name,
functions: vec![],
},
);
}
}

Self {
resolve,
key,
Expand Down
13 changes: 13 additions & 0 deletions tests/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,20 @@ interface baz {
z: func(b: borrow<b>);
}

interface another {
resource yet-another {
hello: func() -> string;
}
resource empty {}
}

world not-used {
export not-exported;
}

world foo {
use another.{yet-another, empty};

resource file {
open: static func(path: string) -> file;
path: func() -> string;
Expand All @@ -223,6 +232,10 @@ world foo {
export baz;
export is-exported;
export is-exported-and-aliased;

export another;
export another-func: func(yet: borrow<yet-another>) -> result;
export another-func-empty: func(empty: borrow<empty>) -> result;
}"#,
true,
)
Expand Down