Merge pull request #168 from nsd20463/embedded_unnamed_types

Embedded unnamed types fix
This commit is contained in:
Vasily Romanov
2018-03-07 10:16:59 +03:00
committed by GitHub
4 changed files with 33 additions and 2 deletions
+3 -1
View File
@@ -23,7 +23,8 @@ generate: root build
.root/src/$(PKG)/tests/data.go \
.root/src/$(PKG)/tests/omitempty.go \
.root/src/$(PKG)/tests/nothing.go \
.root/src/$(PKG)/tests/named_type.go
.root/src/$(PKG)/tests/named_type.go \
.root/src/$(PKG)/tests/embedded_type.go
.root/bin/easyjson -all .root/src/$(PKG)/tests/data.go
.root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go
@@ -33,6 +34,7 @@ generate: root build
.root/bin/easyjson -build_tags=use_easyjson .root/src/$(PKG)/benchmark/data.go
.root/bin/easyjson .root/src/$(PKG)/tests/nested_easy.go
.root/bin/easyjson .root/src/$(PKG)/tests/named_type.go
.root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go
test: generate root
go test \
+5 -1
View File
@@ -284,7 +284,11 @@ func (g *Generator) getType(t reflect.Type) string {
lines := make([]string, 0, nf)
for i := 0; i < nf; i++ {
f := t.Field(i)
line := f.Name + " " + g.getType(f.Type)
var line string
if !f.Anonymous {
line = f.Name + " "
} // else the field is anonymous (an embedded type)
line += g.getType(f.Type)
t := f.Tag
if t != "" {
line += " " + escapeTag(t)
+1
View File
@@ -38,6 +38,7 @@ var testCases = []struct {
{&IntsValue, IntsString},
{&mapStringStringValue, mapStringStringString},
{&namedTypeValue, namedTypeValueString},
{&embeddedTypeValue, embeddedTypeValueString},
{&mapMyIntStringValue, mapMyIntStringValueString},
{&mapIntStringValue, mapIntStringValueString},
{&mapInt32StringValue, mapInt32StringValueString},
+24
View File
@@ -0,0 +1,24 @@
package tests
//easyjson:json
type EmbeddedType struct {
EmbeddedInnerType
Inner struct {
EmbeddedInnerType
}
Field2 int
}
type EmbeddedInnerType struct {
Field1 int
}
var embeddedTypeValue EmbeddedType
func init() {
embeddedTypeValue.Field1 = 1
embeddedTypeValue.Field2 = 2
embeddedTypeValue.Inner.Field1 = 3
}
var embeddedTypeValueString = `{"Inner":{"Field1":3},"Field2":2,"Field1":1}`