invalid_indirect_of_pointer_on_array fix invalid indirect of a pointer on a array

This commit is contained in:
Anthony Regeda
2017-12-19 13:06:15 +03:00
parent 32fa128f23
commit 95baeb8ee7
4 changed files with 23 additions and 4 deletions
+3 -3
View File
@@ -51,7 +51,7 @@ var primitiveStringDecoders = map[reflect.Kind]string{
}
var customDecoders = map[string]string{
"json.Number": "in.JsonNumber()",
"json.Number": "in.JsonNumber()",
}
// genTypeDecoder generates decoding code for the type t, but uses unmarshaler interface if implemented by t.
@@ -88,7 +88,7 @@ func (g *Generator) genTypeDecoder(t reflect.Type, out string, tags fieldTags, i
func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags fieldTags, indent int) error {
ws := strings.Repeat(" ", indent)
// Check whether type is primitive, needs to be done after interface check.
if dec := customDecoders[t.String()]; dec != "" {
if dec := customDecoders[t.String()]; dec != "" {
fmt.Fprintln(g.out, ws+out+" = "+dec)
return nil
} else if dec := primitiveStringDecoders[t.Kind()]; dec != "" && tags.asString {
@@ -170,7 +170,7 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field
fmt.Fprintln(g.out, ws+" for !in.IsDelim(']') {")
fmt.Fprintln(g.out, ws+" if "+iterVar+" < "+fmt.Sprint(length)+" {")
if err := g.genTypeDecoder(elem, out+"["+iterVar+"]", tags, indent+3); err != nil {
if err := g.genTypeDecoder(elem, "("+out+")["+iterVar+"]", tags, indent+3); err != nil {
return err
}
+1 -1
View File
@@ -165,7 +165,7 @@ func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldT
fmt.Fprintln(g.out, ws+" out.RawByte(',')")
fmt.Fprintln(g.out, ws+" }")
if err := g.genTypeEncoder(elem, in+"["+iVar+"]", tags, indent+1, false); err != nil {
if err := g.genTypeEncoder(elem, "("+in+")["+iVar+"]", tags, indent+1, false); err != nil {
return err
}
+1
View File
@@ -47,6 +47,7 @@ var testCases = []struct {
{&mapUint64StringValue, mapUint64StringValueString},
{&mapUintptrStringValue, mapUintptrStringValueString},
{&intKeyedMapStructValue, intKeyedMapStructValueString},
{&intArrayStructValue, intArrayStructValueString},
}
func TestMarshal(t *testing.T) {
+18
View File
@@ -757,3 +757,21 @@ var intKeyedMapStructValueString = `{` +
`"foo":{"42":"life"},` +
`"bar":{"32":{"354634382":"life"}}` +
`}`
type IntArray [2]int
//easyjson:json
type IntArrayStruct struct {
Pointer *IntArray `json:"pointer"`
Value IntArray `json:"value"`
}
var intArrayStructValue = IntArrayStruct{
Pointer: &IntArray{1, 2},
Value: IntArray{1, 2},
}
var intArrayStructValueString = `{` +
`"pointer":[1,2],` +
`"value":[1,2]` +
`}`