From bb584cc9d8163aa54a9efe0b59500ae39a3ffa8a Mon Sep 17 00:00:00 2001 From: "Nicolas S. Dade" Date: Thu, 5 Jan 2017 16:20:26 -0800 Subject: [PATCH] add unit test simplifying the failing case easyjson is mistakenly naming the type of this field 'tests.MyString' in the generated output something about a named type inside an anonmymous type is triggering this bug. --- Makefile | 4 +++- tests/named_type.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/named_type.go diff --git a/Makefile b/Makefile index e2c9bd6..0ebe32f 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,8 @@ generate: root build .root/src/$(PKG)/tests/snake.go \ .root/src/$(PKG)/tests/data.go \ .root/src/$(PKG)/tests/omitempty.go \ - .root/src/$(PKG)/tests/nothing.go + .root/src/$(PKG)/tests/nothing.go \ + .root/src/$(PKG)/tests/named_type.go .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go .root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go @@ -29,6 +30,7 @@ generate: root build .root/bin/easyjson -omit_empty .root/src/$(PKG)/tests/omitempty.go .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 test: generate root go test \ diff --git a/tests/named_type.go b/tests/named_type.go new file mode 100644 index 0000000..a157553 --- /dev/null +++ b/tests/named_type.go @@ -0,0 +1,15 @@ +package tests + +//easyjson:json +type NamedType struct { + Inner struct { + // easyjson is mistakenly naming the type of this field 'tests.MyString' in the generated output + // something about a named type inside an anonmymous type is triggering this bug + Field MyString + } +} + +type MyString string + +var namedTypeValue = NamedType{Inner: struct{ Field MyString }{Field: "test"}} +var namedTypeValueString = `{"Inner":{"Field":"test"}}`