Fix compiler for encoder

This commit is contained in:
Masaaki Goshima 2021-03-19 23:47:29 +09:00
parent ff871cb20d
commit b2bbd63168
2 changed files with 15 additions and 2 deletions

View File

@ -2,7 +2,6 @@ package json_test
import (
"bytes"
"fmt"
"testing"
"github.com/goccy/go-json"
@ -1806,7 +1805,6 @@ func TestCoverBytes(t *testing.T) {
},
}
for _, test := range tests {
fmt.Println("name = ", test.name)
for _, indent := range []bool{true, false} {
for _, htmlEscape := range []bool{true, false} {
var buf bytes.Buffer

View File

@ -92,6 +92,7 @@ func compileHead(ctx *compileContext) (*Opcode, error) {
}
switch typ.Kind() {
case reflect.Slice:
ctx := ctx.withType(typ)
elem := typ.Elem()
if elem.Kind() == reflect.Uint8 {
p := runtime.PtrTo(elem)
@ -117,71 +118,85 @@ func compileHead(ctx *compileContext) (*Opcode, error) {
linkRecursiveCode(code)
return code, nil
case reflect.Int:
ctx := ctx.withType(typ)
if isPtr {
return compileIntPtr(ctx)
}
return compileInt(ctx)
case reflect.Int8:
ctx := ctx.withType(typ)
if isPtr {
return compileInt8Ptr(ctx)
}
return compileInt8(ctx)
case reflect.Int16:
ctx := ctx.withType(typ)
if isPtr {
return compileInt16Ptr(ctx)
}
return compileInt16(ctx)
case reflect.Int32:
ctx := ctx.withType(typ)
if isPtr {
return compileInt32Ptr(ctx)
}
return compileInt32(ctx)
case reflect.Int64:
ctx := ctx.withType(typ)
if isPtr {
return compileInt64Ptr(ctx)
}
return compileInt64(ctx)
case reflect.Uint, reflect.Uintptr:
ctx := ctx.withType(typ)
if isPtr {
return compileUintPtr(ctx)
}
return compileUint(ctx)
case reflect.Uint8:
ctx := ctx.withType(typ)
if isPtr {
return compileUint8Ptr(ctx)
}
return compileUint8(ctx)
case reflect.Uint16:
ctx := ctx.withType(typ)
if isPtr {
return compileUint16Ptr(ctx)
}
return compileUint16(ctx)
case reflect.Uint32:
ctx := ctx.withType(typ)
if isPtr {
return compileUint32Ptr(ctx)
}
return compileUint32(ctx)
case reflect.Uint64:
ctx := ctx.withType(typ)
if isPtr {
return compileUint64Ptr(ctx)
}
return compileUint64(ctx)
case reflect.Float32:
ctx := ctx.withType(typ)
if isPtr {
return compileFloat32Ptr(ctx)
}
return compileFloat32(ctx)
case reflect.Float64:
ctx := ctx.withType(typ)
if isPtr {
return compileFloat64Ptr(ctx)
}
return compileFloat64(ctx)
case reflect.String:
ctx := ctx.withType(typ)
if isPtr {
return compileStringPtr(ctx)
}
return compileString(ctx)
case reflect.Bool:
ctx := ctx.withType(typ)
if isPtr {
return compileBoolPtr(ctx)
}