reflect: ensure all ValueError panics have Kind fields

Этот коммит содержится в:
Damian Gryski 2023-02-28 14:16:25 -08:00 коммит произвёл Damian Gryski
родитель 0ff243e5e2
коммит f9b6f8339b

Просмотреть файл

@ -128,7 +128,7 @@ func (v Value) IsZero() bool {
default: default:
// This should never happens, but will act as a safeguard for // This should never happens, but will act as a safeguard for
// later, as a default value doesn't makes sense here. // later, as a default value doesn't makes sense here.
panic(&ValueError{"reflect.Value.IsZero", v.Kind()}) panic(&ValueError{Method: "reflect.Value.IsZero", Kind: v.Kind()})
} }
} }
@ -169,7 +169,7 @@ func (v Value) IsNil() bool {
_, val := decomposeInterface(*(*interface{})(v.value)) _, val := decomposeInterface(*(*interface{})(v.value))
return val == nil return val == nil
default: default:
panic(&ValueError{Method: "IsNil"}) panic(&ValueError{Method: "IsNil", Kind: v.Kind()})
} }
} }
@ -191,7 +191,7 @@ func (v Value) UnsafePointer() unsafe.Pointer {
case Func: case Func:
panic("unimplemented: (reflect.Value).UnsafePointer()") panic("unimplemented: (reflect.Value).UnsafePointer()")
default: // not implemented: Func default: // not implemented: Func
panic(&ValueError{Method: "UnsafePointer"}) panic(&ValueError{Method: "UnsafePointer", Kind: v.Kind()})
} }
} }
@ -241,7 +241,7 @@ func (v Value) Bool() bool {
return uintptr(v.value) != 0 return uintptr(v.value) != 0
} }
default: default:
panic(&ValueError{Method: "Bool"}) panic(&ValueError{Method: "Bool", Kind: v.Kind()})
} }
} }
@ -278,7 +278,7 @@ func (v Value) Int() int64 {
return int64(int64(uintptr(v.value))) return int64(int64(uintptr(v.value)))
} }
default: default:
panic(&ValueError{Method: "Int"}) panic(&ValueError{Method: "Int", Kind: v.Kind()})
} }
} }
@ -321,7 +321,7 @@ func (v Value) Uint() uint64 {
return uint64(uintptr(v.value)) return uint64(uintptr(v.value))
} }
default: default:
panic(&ValueError{Method: "Uint"}) panic(&ValueError{Method: "Uint", Kind: v.Kind()})
} }
} }
@ -347,7 +347,7 @@ func (v Value) Float() float64 {
return *(*float64)(unsafe.Pointer(&v.value)) return *(*float64)(unsafe.Pointer(&v.value))
} }
default: default:
panic(&ValueError{Method: "Float"}) panic(&ValueError{Method: "Float", Kind: v.Kind()})
} }
} }
@ -369,7 +369,7 @@ func (v Value) Complex() complex128 {
// architectures with 128-bit pointers, however. // architectures with 128-bit pointers, however.
return *(*complex128)(v.value) return *(*complex128)(v.value)
default: default:
panic(&ValueError{Method: "Complex"}) panic(&ValueError{Method: "Complex", Kind: v.Kind()})
} }
} }
@ -455,7 +455,7 @@ func (v Value) Slice(i, j int) Value {
} }
} }
panic(&ValueError{"Slice", v.Kind()}) panic(&ValueError{Method: "Slice", Kind: v.Kind()})
} }
func (v Value) Slice3(i, j, k int) Value { func (v Value) Slice3(i, j, k int) Value {
@ -510,7 +510,7 @@ func (v Value) Len() int {
case String: case String:
return int((*stringHeader)(v.value).len) return int((*stringHeader)(v.value).len)
default: default:
panic(&ValueError{Method: "Len"}) panic(&ValueError{Method: "Len", Kind: v.Kind()})
} }
} }
@ -528,7 +528,7 @@ func (v Value) Cap() int {
case Slice: case Slice:
return int((*sliceHeader)(v.value).cap) return int((*sliceHeader)(v.value).cap)
default: default:
panic(&ValueError{Method: "Cap"}) panic(&ValueError{Method: "Cap", Kind: v.Kind()})
} }
} }
@ -558,7 +558,7 @@ func (v Value) Elem() Value {
flags: v.flags &^ valueFlagIndirect, flags: v.flags &^ valueFlagIndirect,
} }
default: default:
panic(&ValueError{Method: "Elem"}) panic(&ValueError{Method: "Elem", Kind: v.Kind()})
} }
} }
@ -707,7 +707,7 @@ func (v Value) Index(i int) Value {
value: unsafe.Pointer(value), value: unsafe.Pointer(value),
} }
default: default:
panic(&ValueError{Method: "Index"}) panic(&ValueError{Method: "Index", Kind: v.Kind()})
} }
} }
@ -745,7 +745,7 @@ func (v Value) OverflowFloat(x float64) bool {
case Float64: case Float64:
return false return false
} }
panic(&ValueError{"reflect.Value.OverflowFloat", v.Kind()}) panic(&ValueError{Method: "reflect.Value.OverflowFloat", Kind: v.Kind()})
} }
func overflowFloat32(x float64) bool { func overflowFloat32(x float64) bool {
@ -891,7 +891,7 @@ func (v Value) SetBool(x bool) {
case Bool: case Bool:
*(*bool)(v.value) = x *(*bool)(v.value) = x
default: default:
panic(&ValueError{Method: "SetBool"}) panic(&ValueError{Method: "SetBool", Kind: v.Kind()})
} }
} }
@ -909,7 +909,7 @@ func (v Value) SetInt(x int64) {
case Int64: case Int64:
*(*int64)(v.value) = x *(*int64)(v.value) = x
default: default:
panic(&ValueError{Method: "SetInt"}) panic(&ValueError{Method: "SetInt", Kind: v.Kind()})
} }
} }
@ -929,7 +929,7 @@ func (v Value) SetUint(x uint64) {
case Uintptr: case Uintptr:
*(*uintptr)(v.value) = uintptr(x) *(*uintptr)(v.value) = uintptr(x)
default: default:
panic(&ValueError{Method: "SetUint"}) panic(&ValueError{Method: "SetUint", Kind: v.Kind()})
} }
} }
@ -941,7 +941,7 @@ func (v Value) SetFloat(x float64) {
case Float64: case Float64:
*(*float64)(v.value) = x *(*float64)(v.value) = x
default: default:
panic(&ValueError{Method: "SetFloat"}) panic(&ValueError{Method: "SetFloat", Kind: v.Kind()})
} }
} }
@ -953,7 +953,7 @@ func (v Value) SetComplex(x complex128) {
case Complex128: case Complex128:
*(*complex128)(v.value) = x *(*complex128)(v.value) = x
default: default:
panic(&ValueError{Method: "SetComplex"}) panic(&ValueError{Method: "SetComplex", Kind: v.Kind()})
} }
} }
@ -963,7 +963,7 @@ func (v Value) SetString(x string) {
case String: case String:
*(*string)(v.value) = x *(*string)(v.value) = x
default: default:
panic(&ValueError{Method: "SetString"}) panic(&ValueError{Method: "SetString", Kind: v.Kind()})
} }
} }
@ -977,7 +977,7 @@ func (v Value) SetCap(n int) {
func (v Value) SetLen(n int) { func (v Value) SetLen(n int) {
if v.typecode.Kind() != Slice { if v.typecode.Kind() != Slice {
panic(&ValueError{"reflect.Value.SetLen", v.Kind()}) panic(&ValueError{Method: "reflect.Value.SetLen", Kind: v.Kind()})
} }
hdr := (*sliceHeader)(v.value) hdr := (*sliceHeader)(v.value)
@ -1002,7 +1002,7 @@ func (v Value) OverflowInt(x int64) bool {
trunc := (x << (64 - bitSize)) >> (64 - bitSize) trunc := (x << (64 - bitSize)) >> (64 - bitSize)
return x != trunc return x != trunc
} }
panic(&ValueError{"reflect.Value.OverflowInt", v.Kind()}) panic(&ValueError{Method: "reflect.Value.OverflowInt", Kind: v.Kind()})
} }
// OverflowUint reports whether the uint64 x cannot be represented by v's type. // OverflowUint reports whether the uint64 x cannot be represented by v's type.
@ -1015,7 +1015,7 @@ func (v Value) OverflowUint(x uint64) bool {
trunc := (x << (64 - bitSize)) >> (64 - bitSize) trunc := (x << (64 - bitSize)) >> (64 - bitSize)
return x != trunc return x != trunc
} }
panic(&ValueError{"reflect.Value.OverflowUint", v.Kind()}) panic(&ValueError{Method: "reflect.Value.OverflowUint", Kind: v.Kind()})
} }
func (v Value) Convert(t Type) Value { func (v Value) Convert(t Type) Value {
@ -1381,7 +1381,7 @@ func MakeMapWithSize(typ Type, n int) Value {
) )
if typ.Kind() != Map { if typ.Kind() != Map {
panic(&ValueError{"MakeMap", typ.Kind()}) panic(&ValueError{Method: "MakeMap", Kind: typ.Kind()})
} }
if n < 0 { if n < 0 {