Skip to content

Commit

Permalink
fix resource-own-in-other-interface test for C
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Oct 5, 2023
1 parent 989259f commit a253be7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
84 changes: 82 additions & 2 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,7 @@ impl C {
}
_ => {}
}
self.public_anonymous_types.insert(*id);
self.private_anonymous_types.remove(id);
self.visit_anonymous_types(resolve, &Type::Id(*id));
dst.push_str(&ns);
dst.push_str("_");
push_ty_name(
Expand All @@ -1057,6 +1056,87 @@ impl C {
}
}
}

fn visit_anonymous_types(&mut self, resolve: &Resolve, ty: &Type) {
match ty {
Type::String => {
self.needs_string = true;
}
Type::Id(id) => {
let ty = &resolve.types[*id];
if ty.name.is_none() {
match &ty.kind {
TypeDefKind::Type(_) => {}
TypeDefKind::Handle(Handle::Borrow(resource))
if matches!(
self.resources
.get(&dealias(resolve, *resource))
.map(|info| &info.direction),
Some(Direction::Export)
) => {}
_ => {
self.public_anonymous_types.insert(*id);
self.private_anonymous_types.remove(id);
}
}
}

match &ty.kind {
TypeDefKind::Type(t) => self.visit_anonymous_types(resolve, t),
TypeDefKind::Record(r) => {
for field in &r.fields {
self.visit_anonymous_types(resolve, &field.ty);
}
}
TypeDefKind::Resource
| TypeDefKind::Handle(_)
| TypeDefKind::Flags(_)
| TypeDefKind::Enum(_) => {}
TypeDefKind::Variant(v) => {
for case in &v.cases {
if let Some(ty) = &case.ty {
self.visit_anonymous_types(resolve, ty);
}
}
}
TypeDefKind::Tuple(t) => {
for ty in &t.types {
self.visit_anonymous_types(resolve, ty);
}
}
TypeDefKind::Option(ty) => {
self.visit_anonymous_types(resolve, ty);
}
TypeDefKind::Result(r) => {
if let Some(ty) = &r.ok {
self.visit_anonymous_types(resolve, ty);
}
if let Some(ty) = &r.err {
self.visit_anonymous_types(resolve, ty);
}
}
TypeDefKind::List(ty) => {
self.visit_anonymous_types(resolve, ty);
}
TypeDefKind::Future(ty) => {
if let Some(ty) = ty {
self.visit_anonymous_types(resolve, ty);
}
}
TypeDefKind::Stream(s) => {
if let Some(ty) = &s.element {
self.visit_anonymous_types(resolve, ty);
}
if let Some(ty) = &s.end {
self.visit_anonymous_types(resolve, ty);
}
}
TypeDefKind::Unknown => unreachable!(),
}
}
_ => {}
}
}
}

pub fn push_ty_name(
Expand Down
1 change: 1 addition & 0 deletions crates/go/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ macro_rules! codegen_test {
(resource_local_alias_borrow_import $name:tt $test:tt) => {};
(resource_borrow_in_record $name:tt $test:tt) => {};
(resource_borrow_in_record_export $name:tt $test:tt) => {};
(resource_own_in_other_interface $name:tt $test:tt) => {};
(resources_in_aggregates $name:tt $test:tt) => {};
(issue668 $name:tt $test:tt) => {};

Expand Down
1 change: 1 addition & 0 deletions crates/teavm-java/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ macro_rules! codegen_test {
(resource_local_alias_borrow_import $name:tt $test:tt) => {};
(resource_borrow_in_record $name:tt $test:tt) => {};
(resource_borrow_in_record_export $name:tt $test:tt) => {};
(resource_own_in_other_interface $name:tt $test:tt) => {};
(same_names5 $name:tt $test:tt) => {};
(resources_in_aggregates $name:tt $test:tt) => {};
(issue668 $name:tt $test:tt) => {};
Expand Down

0 comments on commit a253be7

Please sign in to comment.