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
6 changes: 3 additions & 3 deletions crates/core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ impl Types {
(TypeDefKind::Handle(_), _) => false,
(TypeDefKind::Unknown, _) => unreachable!(),

// TODO: for now consider all resources not-equal to each other.
// This is because the same type id can be used for both an imported
// and exported resource where those should be distinct types.
// Resources are only equal if their original ids are equal,
// otherwise all resources are un-equal to each other.
(TypeDefKind::Resource, TypeDefKind::Resource) => a == b,
(TypeDefKind::Resource, _) => false,
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/runtime/rust/equal-types/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,24 @@ impl HGuest for Component {
x
}
}

const _: () = {
use crate::exports::test::equal_types::resources::*;

struct GuestResource;

impl Guest for Component {
type R1 = GuestResource;

// Intentionally swap the 1/2 relative to WIT to ensure that the types
// are equivalent.
fn alias_own(x: T2) -> T1 {
x
}
fn alias_aggregate(x: Option<T2>) -> Option<T1> {
x
}
}

impl GuestR1 for GuestResource {}
};
11 changes: 11 additions & 0 deletions tests/runtime/rust/equal-types/test.wit
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,20 @@ interface blah {
alias-type: func(x: r1) -> r2;
}

interface resources {
resource r1;
type r2 = r1;

record t1 { a: r1 }
record t2 { a: r2 }
alias-own: func(x: t1) -> t2;
alias-aggregate: func(x: option<t1>) -> option<t2>;
}

world host {
export blah;
export blag;
export resources;
}
world proxy {
import blag;
Expand Down
Loading