Skip to content
Closed
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
11 changes: 10 additions & 1 deletion crates/rust/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,16 @@ unsafe fn call_import(&mut self, _params: Self::ParamsLower, _results: *mut u8)
}

match ty {
Type::Id(t) => self.print_tyid(*t, mode),
Type::Id(t) => {
// When generating names for stream/future payload types, dealias
// all inner type references so that `use`d type aliases from
// different interfaces resolve to the same canonical type
let t = match self.identifier {
Identifier::StreamOrFuturePayload => dealias(self.resolve, *t),
_ => *t,
};
self.print_tyid(t, mode)
}
Type::Bool => self.push_str("bool"),
Type::U8 => self.push_str("u8"),
Type::U16 => self.push_str("u16"),
Expand Down
1 change: 1 addition & 0 deletions crates/rust/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,4 @@ mod retyped_list {
}
});
}

15 changes: 15 additions & 0 deletions tests/codegen/import-export-future.wit
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,28 @@ package a:b;
world w {
import i;
export i;
import j;
import k;
}

interface i {
use t.{r};
f: func(p: future<r>);
}

// Multiple interfaces `use`-ing the same type from a shared interface
// and wrapping it in an anonymous type (result<_, r>) ensures that
// dealiasing resolves inner types, not just top-level payload types.
interface j {
use t.{r};
f: func() -> future<result<_, r>>;
}

interface k {
use t.{r};
f: func() -> future<result<_, r>>;
}

interface t {
record r {
x: u32,
Expand Down
15 changes: 15 additions & 0 deletions tests/codegen/import-export-stream.wit
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,28 @@ package a:b;
world w {
import i;
export i;
import j;
import k;
}

interface i {
use t.{r};
f: func(p: stream<r>);
}

// Multiple interfaces `use`-ing the same type from a shared interface
// and wrapping it in an anonymous type (result<_, r>) ensures that
// dealiasing resolves inner types, not just top-level payload types.
interface j {
use t.{r};
f: func() -> stream<result<_, r>>;
}

interface k {
use t.{r};
f: func() -> stream<result<_, r>>;
}

interface t {
record r {
x: u32,
Expand Down
Loading