runtime/internal/lib/reflect: fix Field closure kind to func

This commit is contained in:
visualfc
2025-09-26 10:18:23 +08:00
parent 8959c83397
commit ccaf59ec62
2 changed files with 14 additions and 1 deletions

View File

@@ -39,4 +39,12 @@ func main() {
panic(fmt.Sprintf("not func: %T", fn)) panic(fmt.Sprintf("not func: %T", fn))
} }
} }
v := reflect.ValueOf(T{})
if v.Field(0).Kind() != reflect.Func {
panic("must func")
}
}
type T struct {
fn func(int)
} }

View File

@@ -600,8 +600,13 @@ func (v Value) Field(i int) Value {
field := &tt.Fields[i] field := &tt.Fields[i]
typ := field.Typ typ := field.Typ
// Check closure to func
kind := typ.Kind()
if typ.IsClosure() {
kind = abi.Func
}
// Inherit permission bits from v, but clear flagEmbedRO. // Inherit permission bits from v, but clear flagEmbedRO.
fl := v.flag&(flagStickyRO|flagIndir|flagAddr) | flag(typ.Kind()) fl := v.flag&(flagStickyRO|flagIndir|flagAddr) | flag(kind)
// Using an unexported field forces flagRO. // Using an unexported field forces flagRO.
if !field.Exported() { if !field.Exported() {
if field.Embedded() { if field.Embedded() {