Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (e *InvalidUnmarshalError) Error() string {
return "json: Unmarshal(nil)"
}

if e.Type.Kind() != reflect.Ptr {
if e.Type.Kind() != reflect.Pointer {
return "json: Unmarshal(non-pointer " + e.Type.String() + ")"
}
return "json: Unmarshal(nil " + e.Type.String() + ")"
Expand All @@ -176,7 +176,7 @@ func (d *decodeState) unmarshal(v any) (err error) {
}()

rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
if rv.Kind() != reflect.Pointer || rv.IsNil() {
return &InvalidUnmarshalError{reflect.TypeOf(v)}
}

Expand Down Expand Up @@ -436,25 +436,25 @@ func (d *decodeState) indirect(v reflect.Value, decodingNull bool) (Unmarshaler,
// If v is a named type and is addressable,
// start with its address, so that if the type has pointer methods,
// we find them.
if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() {
if v.Kind() != reflect.Pointer && v.Type().Name() != "" && v.CanAddr() {
v = v.Addr()
}
for {
// Load value from interface, but only if the result will be
// usefully addressable.
if v.Kind() == reflect.Interface && !v.IsNil() {
e := v.Elem()
if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodingNull || e.Elem().Kind() == reflect.Ptr) {
if e.Kind() == reflect.Pointer && !e.IsNil() && (!decodingNull || e.Elem().Kind() == reflect.Pointer) {
v = e
continue
}
}

if v.Kind() != reflect.Ptr {
if v.Kind() != reflect.Pointer {
break
}

if v.Elem().Kind() != reflect.Ptr && decodingNull && v.CanSet() {
if v.Elem().Kind() != reflect.Pointer && decodingNull && v.CanSet() {
break
}
if v.IsNil() {
Expand Down Expand Up @@ -695,7 +695,7 @@ func (d *decodeState) object(v reflect.Value) {
subv = v
destring = f.quoted
for _, i := range f.index {
if subv.Kind() == reflect.Ptr {
if subv.Kind() == reflect.Pointer {
if subv.IsNil() {
subv.Set(reflect.New(subv.Type().Elem()))
}
Expand Down Expand Up @@ -877,7 +877,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
break
}
switch v.Kind() {
case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice:
case reflect.Interface, reflect.Pointer, reflect.Map, reflect.Slice:
v.Set(reflect.Zero(v.Type()))
// otherwise, ignore null for primitives/string
default:
Expand Down
18 changes: 9 additions & 9 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func isEmptyValue(v reflect.Value) bool {
return v.Uint() == 0
case reflect.Float32, reflect.Float64:
return v.Float() == 0
case reflect.Interface, reflect.Ptr:
case reflect.Interface, reflect.Pointer:
return v.IsNil()
default:
}
Expand Down Expand Up @@ -388,7 +388,7 @@ func newTypeEncoder(t reflect.Type, allowAddr bool) encoderFunc {
if t.Implements(marshalerType) {
return marshalerEncoder
}
if t.Kind() != reflect.Ptr && allowAddr {
if t.Kind() != reflect.Pointer && allowAddr {
if reflect.PointerTo(t).Implements(marshalerType) {
return newCondAddrEncoder(addrMarshalerEncoder, newTypeEncoder(t, false))
}
Expand All @@ -397,7 +397,7 @@ func newTypeEncoder(t reflect.Type, allowAddr bool) encoderFunc {
if t.Implements(textMarshalerType) {
return textMarshalerEncoder
}
if t.Kind() != reflect.Ptr && allowAddr {
if t.Kind() != reflect.Pointer && allowAddr {
if reflect.PointerTo(t).Implements(textMarshalerType) {
return newCondAddrEncoder(addrTextMarshalerEncoder, newTypeEncoder(t, false))
}
Expand Down Expand Up @@ -430,7 +430,7 @@ func newTypeEncoder(t reflect.Type, allowAddr bool) encoderFunc {
return newSliceEncoder(t)
case reflect.Array:
return newArrayEncoder(t)
case reflect.Ptr:
case reflect.Pointer:
return newPtrEncoder(t)
default:
return unsupportedTypeEncoder
Expand All @@ -442,7 +442,7 @@ func invalidValueEncoder(e *encodeState, v reflect.Value, _ encOpts) {
}

func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
if v.Kind() == reflect.Ptr && v.IsNil() {
if v.Kind() == reflect.Pointer && v.IsNil() {
e.WriteString("null")
return
}
Expand Down Expand Up @@ -479,7 +479,7 @@ func addrMarshalerEncoder(e *encodeState, v reflect.Value, _ encOpts) {
}

func textMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
if v.Kind() == reflect.Ptr && v.IsNil() {
if v.Kind() == reflect.Pointer && v.IsNil() {
e.WriteString("null")
return
}
Expand Down Expand Up @@ -855,7 +855,7 @@ func isValidTag(s string) bool {

func fieldByIndex(v reflect.Value, index []int) reflect.Value {
for _, i := range index {
if v.Kind() == reflect.Ptr {
if v.Kind() == reflect.Pointer {
if v.IsNil() {
return reflect.Value{}
}
Expand All @@ -868,7 +868,7 @@ func fieldByIndex(v reflect.Value, index []int) reflect.Value {

func typeByIndex(t reflect.Type, index []int) reflect.Type {
for _, i := range index {
if t.Kind() == reflect.Ptr {
if t.Kind() == reflect.Pointer {
t = t.Elem()
}
t = t.Field(i).Type
Expand Down Expand Up @@ -1171,7 +1171,7 @@ func typeFields(t reflect.Type) []field {
index[len(f.index)] = i

ft := sf.Type
if ft.Name() == "" && ft.Kind() == reflect.Ptr {
if ft.Name() == "" && ft.Kind() == reflect.Pointer {
// Follow pointer.
ft = ft.Elem()
}
Expand Down
5 changes: 1 addition & 4 deletions scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ func genString(stddev float64) string {
}

func genArray(n int) []any {
f := min(int(math.Abs(rand.NormFloat64())*math.Min(10, float64(n/2))), n)
if f < 1 {
f = 1
}
f := max(min(int(math.Abs(rand.NormFloat64())*math.Min(10, float64(n/2))), n), 1)
x := make([]any, f)
for i := range x {
x[i] = genValue(((i+1)*n)/f - (i*n)/f)
Expand Down
Loading