Merge pull request #988 from visualfc/reflect_typeof

runtime/internal/lib/reflect: fix TypeOf check nil
This commit is contained in:
xushiwei
2025-02-13 15:20:24 +08:00
committed by GitHub

View File

@@ -811,7 +811,11 @@ func (t *structType) FieldByName(name string) (f StructField, present bool) {
// If i is a nil interface value, TypeOf returns nil. // If i is a nil interface value, TypeOf returns nil.
func TypeOf(i any) Type { func TypeOf(i any) Type {
eface := *(*emptyInterface)(unsafe.Pointer(&i)) eface := *(*emptyInterface)(unsafe.Pointer(&i))
// closure type // check nil
if eface.typ == nil {
return nil
}
// check closure type
if eface.typ.IsClosure() { if eface.typ.IsClosure() {
ft := eface.typ.StructType().Fields[0].Typ.FuncType() ft := eface.typ.StructType().Fields[0].Typ.FuncType()
return toType(&ft.Type) return toType(&ft.Type)