runtime/internal/lib/reflect: fix TypeOf check closure

This commit is contained in:
visualfc
2025-02-13 10:15:58 +08:00
parent 0a9dfdc5c0
commit 368c7d6cda

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)