Skip to content

Commit 74a0b4a

Browse files
authored
Fix the package listed for cloned interfaces (#2449)
Addresses bytecodealliance/wit-bindgen#1540 at the source here in wasm-tools, a but with `generate_nominal_type_ids`.
1 parent 4212768 commit 74a0b4a

3 files changed

Lines changed: 124 additions & 0 deletions

File tree

crates/wit-parser/src/resolve/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,6 +2644,7 @@ package {name} is defined in two different locations:\n\
26442644
// above) and the `CloneMaps` are shared amongst interfaces. This
26452645
// means that future clones will use the types produced here too.
26462646
let mut new_id = id;
2647+
cloner.new_package = cloner.resolve.interfaces[new_id].package;
26472648
cloner.interface(&mut new_id);
26482649

26492650
// Load up the previous `key` and go ahead and mutate the

tests/cli/nominal4.wit

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: component wit --generate-nominal-type-ids foo % --json
2+
3+
package a:b;
4+
5+
world foo {
6+
import other:c/x;
7+
export other:c/x;
8+
}
9+
10+
package other:c {
11+
interface x {
12+
resource r;
13+
hi: func() -> r;
14+
}
15+
}

tests/cli/nominal4.wit.stdout

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"worlds": [
3+
{
4+
"name": "foo",
5+
"imports": {
6+
"interface-0": {
7+
"interface": {
8+
"id": 0
9+
}
10+
}
11+
},
12+
"exports": {
13+
"interface-1": {
14+
"interface": {
15+
"id": 1
16+
}
17+
}
18+
},
19+
"package": 1
20+
}
21+
],
22+
"interfaces": [
23+
{
24+
"name": "x",
25+
"types": {
26+
"r": 0
27+
},
28+
"functions": {
29+
"hi": {
30+
"name": "hi",
31+
"kind": "freestanding",
32+
"params": [],
33+
"result": 1
34+
}
35+
},
36+
"package": 0
37+
},
38+
{
39+
"name": "x",
40+
"types": {
41+
"r": 2
42+
},
43+
"functions": {
44+
"hi": {
45+
"name": "hi",
46+
"kind": "freestanding",
47+
"params": [],
48+
"result": 3
49+
}
50+
},
51+
"package": 0,
52+
"clone_of": 0
53+
}
54+
],
55+
"types": [
56+
{
57+
"name": "r",
58+
"kind": "resource",
59+
"owner": {
60+
"interface": 0
61+
}
62+
},
63+
{
64+
"name": null,
65+
"kind": {
66+
"handle": {
67+
"own": 0
68+
}
69+
},
70+
"owner": null
71+
},
72+
{
73+
"name": "r",
74+
"kind": "resource",
75+
"owner": {
76+
"interface": 1
77+
}
78+
},
79+
{
80+
"name": null,
81+
"kind": {
82+
"handle": {
83+
"own": 2
84+
}
85+
},
86+
"owner": null
87+
}
88+
],
89+
"packages": [
90+
{
91+
"name": "other:c",
92+
"interfaces": {
93+
"x": 0
94+
},
95+
"worlds": {}
96+
},
97+
{
98+
"name": "a:b",
99+
"docs": {
100+
"contents": "RUN: component wit --generate-nominal-type-ids foo % --json"
101+
},
102+
"interfaces": {},
103+
"worlds": {
104+
"foo": 0
105+
}
106+
}
107+
]
108+
}

0 commit comments

Comments
 (0)