Skip to content

Commit 57fb361

Browse files
authored
Merge pull request #42 from ReconfigureIO/bugfix/interface-types
Fix interface type dumping.
2 parents 7d9eff6 + 8988695 commit 57fb361

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
func main() {
4+
item := map[string]interface{}{
5+
"foo": "bar",
6+
"baz": 400,
7+
}
8+
9+
println(item["foo"])
10+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{
2+
"all-comments": [],
3+
"comments": [],
4+
"declarations": [
5+
{
6+
"body": [
7+
{
8+
"kind": "statement",
9+
"left": [
10+
{
11+
"kind": "expression",
12+
"type": "identifier",
13+
"value": {
14+
"kind": "ident",
15+
"value": "item"
16+
}
17+
}
18+
],
19+
"right": [
20+
{
21+
"declared": {
22+
"key": {
23+
"kind": "type",
24+
"type": "identifier",
25+
"value": {
26+
"kind": "ident",
27+
"value": "string"
28+
}
29+
},
30+
"kind": "type",
31+
"type": "map",
32+
"value": {
33+
"incomplete": false,
34+
"kind": "type",
35+
"methods": [],
36+
"type": "interface"
37+
}
38+
},
39+
"kind": "literal",
40+
"type": "composite",
41+
"values": [
42+
{
43+
"key": {
44+
"kind": "literal",
45+
"type": "STRING",
46+
"value": "\"foo\""
47+
},
48+
"kind": "expression",
49+
"type": "key-value",
50+
"value": {
51+
"kind": "literal",
52+
"type": "STRING",
53+
"value": "\"bar\""
54+
}
55+
},
56+
{
57+
"key": {
58+
"kind": "literal",
59+
"type": "STRING",
60+
"value": "\"baz\""
61+
},
62+
"kind": "expression",
63+
"type": "key-value",
64+
"value": {
65+
"kind": "literal",
66+
"type": "INT",
67+
"value": "400"
68+
}
69+
}
70+
]
71+
}
72+
],
73+
"type": "define"
74+
},
75+
{
76+
"kind": "statement",
77+
"type": "expression",
78+
"value": {
79+
"arguments": [
80+
{
81+
"index": {
82+
"kind": "literal",
83+
"type": "STRING",
84+
"value": "\"foo\""
85+
},
86+
"kind": "expression",
87+
"target": {
88+
"kind": "expression",
89+
"type": "identifier",
90+
"value": {
91+
"kind": "ident",
92+
"value": "item"
93+
}
94+
},
95+
"type": "index"
96+
}
97+
],
98+
"ellipsis": false,
99+
"function": {
100+
"kind": "expression",
101+
"type": "identifier",
102+
"value": {
103+
"kind": "ident",
104+
"value": "println"
105+
}
106+
},
107+
"kind": "expression",
108+
"type": "call"
109+
}
110+
}
111+
],
112+
"comments": [],
113+
"kind": "decl",
114+
"name": {
115+
"kind": "ident",
116+
"value": "main"
117+
},
118+
"params": [],
119+
"results": null,
120+
"type": "function"
121+
}
122+
],
123+
"imports": [],
124+
"kind": "file",
125+
"name": {
126+
"kind": "ident",
127+
"value": "main"
128+
}
129+
}

goblin.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ func AttemptExprAsType(e ast.Expr, fset *token.FileSet) map[string]interface{} {
114114
}
115115
}
116116

117+
if n, ok := e.(*ast.InterfaceType); ok {
118+
return map[string]interface{}{
119+
"kind": "type",
120+
"type": "interface",
121+
"incomplete": n.Incomplete,
122+
"methods": DumpFields(n.Methods, fset),
123+
}
124+
}
125+
117126
if n, ok := e.(*ast.MapType); ok {
118127
return map[string]interface{}{
119128
"kind": "type",

goblin_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func TestPackageFixtures(t *testing.T) {
6666
"fixtures/packages/methoddecl/method.go",
6767
"fixtures/packages/methoddecl/method.json",
6868
},
69+
Fixture{
70+
"map with interface type",
71+
"fixtures/packages/interface_type/interface.go",
72+
"fixtures/packages/interface_type/interface.json",
73+
},
6974
}
7075

7176
for _, fix := range fixtures {

0 commit comments

Comments
 (0)