Skip to content

Commit 3aa5739

Browse files
committed
testdata/issues, wit/bindgen: test for #242
Predeclare Tag method on variant types.
1 parent 1515949 commit 3aa5739

File tree

4 files changed

+104
-2
lines changed

4 files changed

+104
-2
lines changed

testdata/issues/issue242.wit

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package issues:issue242;
2+
3+
interface i {
4+
variant v {
5+
a,
6+
b,
7+
// tag might collide with (cm.Variant).Tag() method
8+
tag,
9+
%string(string),
10+
}
11+
}
12+
13+
world w {
14+
import i;
15+
}

testdata/issues/issue242.wit.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"worlds": [
3+
{
4+
"name": "w",
5+
"imports": {
6+
"interface-0": {
7+
"interface": {
8+
"id": 0
9+
}
10+
}
11+
},
12+
"exports": {},
13+
"package": 0
14+
}
15+
],
16+
"interfaces": [
17+
{
18+
"name": "i",
19+
"types": {
20+
"v": 0
21+
},
22+
"functions": {},
23+
"package": 0
24+
}
25+
],
26+
"types": [
27+
{
28+
"name": "v",
29+
"kind": {
30+
"variant": {
31+
"cases": [
32+
{
33+
"name": "a",
34+
"type": null
35+
},
36+
{
37+
"name": "b",
38+
"type": null
39+
},
40+
{
41+
"name": "tag",
42+
"type": null,
43+
"docs": {
44+
"contents": "tag might collide with (cm.Variant).Tag() method"
45+
}
46+
},
47+
{
48+
"name": "string",
49+
"type": "string"
50+
}
51+
]
52+
}
53+
},
54+
"owner": {
55+
"interface": 0
56+
}
57+
}
58+
],
59+
"packages": [
60+
{
61+
"name": "issues:issue242",
62+
"interfaces": {
63+
"i": 0
64+
},
65+
"worlds": {
66+
"w": 0
67+
}
68+
}
69+
]
70+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package issues:issue242;
2+
3+
interface i {
4+
variant v {
5+
a,
6+
b,
7+
/// tag might collide with (cm.Variant).Tag() method
8+
tag,
9+
%string(string),
10+
}
11+
}
12+
13+
world w {
14+
import i;
15+
}

wit/bindgen/generator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,11 @@ func (g *generator) declareTypeDef(file *gen.File, dir wit.Direction, t *wit.Typ
539539

540540
// Predeclare reserved methods.
541541
switch t.Kind.(type) {
542+
case *wit.Enum:
543+
decl.scope.DeclareName("String") // For fmt.Stringer
542544
case *wit.Variant:
543-
decl.scope.DeclareName("Tag")
545+
decl.scope.DeclareName("Tag") // Method on cm.Variant
546+
decl.scope.DeclareName("String") // For fmt.Stringer
544547
}
545548

546549
return decl, nil
@@ -836,7 +839,6 @@ func (g *generator) variantRep(file *gen.File, dir wit.Direction, t *wit.TypeDef
836839

837840
decl, _ := g.typeDecl(dir, t)
838841
scope := decl.scope
839-
scope.DeclareName("String") // For fmt.Stringer
840842

841843
// Emit type
842844
var b strings.Builder

0 commit comments

Comments
 (0)