Skip to content

Commit cedfa66

Browse files
committed
fixes
1 parent d69a4c1 commit cedfa66

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

parser_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ func (r *parser) EvalType(expr ast.Expr) (ret Type) {
144144
continue
145145
}
146146
for _, name := range v.Names {
147+
n := name.Name
148+
if n == "" {
149+
n = "_"
150+
}
147151
t := &typeStructField{
148-
name: name.Name,
152+
name: n,
149153
elem: ty,
150154
tag: tag,
151155
}

types_interface.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package gotype
22

3-
import "bytes"
3+
import (
4+
"bytes"
5+
)
46

57
type typeInterface struct {
68
typeBase
@@ -14,7 +16,7 @@ func (t *typeInterface) String() string {
1416
buf.WriteString("interface{")
1517
for i, v := range t.all {
1618
if i != 0 {
17-
buf.WriteByte(' ')
19+
buf.WriteString("; ")
1820
}
1921
buf.WriteString(v.String())
2022
}
@@ -40,6 +42,7 @@ func (t *typeInterface) MethodByName(name string) (Type, bool) {
4042
return b, true
4143
}
4244
for _, v := range t.anonymo {
45+
v := v.Declaration()
4346
b, ok := v.MethodByName(name)
4447
if ok {
4548
return b, true

types_struct.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (t *typeStruct) String() string {
1414
buf.WriteString("struct{")
1515
for i, v := range t.fields {
1616
if i != 0 {
17-
buf.WriteByte(' ')
17+
buf.WriteString("; ")
1818
}
1919
buf.WriteString(v.String())
2020
}

types_struct_field.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ type typeStructField struct {
1414
}
1515

1616
func (t *typeStructField) String() string {
17-
return fmt.Sprintf("%v %v `%v`", t.name, t.elem, t.tag)
17+
tag := ""
18+
if t.tag != "" {
19+
tag = " `" + string(t.tag) + "`"
20+
}
21+
if t.anonymous {
22+
return fmt.Sprintf("%v%s", t.elem, tag)
23+
}
24+
return fmt.Sprintf("%v %v%s", t.name, t.elem, tag)
1825
}
1926

2027
func (t *typeStructField) Name() string {

0 commit comments

Comments
 (0)