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
11 changes: 11 additions & 0 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,17 @@ fn is_prim_type(resolve: &Resolve, ty: &Type) -> bool {
}

fn is_prim_type_id(resolve: &Resolve, id: TypeId) -> bool {
// A named type contributes its (interface-local) name to the generated
// type name rather than its structure, so even when its underlying
// representation is primitive it must not be treated as a world-shareable
// "primitive" type. Otherwise two interfaces that each define a
// differently-typed but identically-named type (e.g. `field-value` in two
// versions of `wasi:http/types`) collapse onto the same anonymous type
// name, producing structs with incompatible element pointer types.
// See https://github.com/bytecodealliance/wit-bindgen/issues/1621.
if resolve.types[id].name.is_some() {
return false;
}
match &resolve.types[id].kind {
TypeDefKind::List(elem) => is_prim_type(resolve, elem),

Expand Down
16 changes: 16 additions & 0 deletions tests/codegen/issue-1621.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package my:test;

interface a {
type t = list<u8>;
f: func() -> list<t>;
}

interface b {
type t = list<u8>;
g: func() -> list<t>;
}

world w {
import a;
import b;
}
2 changes: 1 addition & 1 deletion tests/runtime/flavorful/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void exports_runner_run() {
test_list_typedef3_t b;
b.ptr = &b_str;
b.len = 1;
runner_tuple2_list_typedef2_list_typedef3_t ret;
test_tuple2_list_typedef2_list_typedef3_t ret;
test_list_typedefs(&a, &b, &ret);

assert(memcmp(ret.f0.ptr, "typedef3", ret.f0.len) == 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/runtime/flavorful/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool exports_test_errno_result(exports_test_my_errno_t *err) {
void exports_test_list_typedefs(
exports_test_list_typedef_t *a,
exports_test_list_typedef3_t *c,
test_tuple2_list_typedef2_list_typedef3_t *ret) {
exports_test_tuple2_list_typedef2_list_typedef3_t *ret) {
assert(memcmp(a->ptr, "typedef1", a->len) == 0);
exports_test_list_typedef_free(a);

Expand Down
Loading