internal/lib/reflect: Value.Type

This commit is contained in:
visualfc
2024-10-11 09:02:09 +08:00
parent d946ba426e
commit 515057c41a
3 changed files with 3897 additions and 3631 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -553,6 +553,22 @@ func (t *Type) InterfaceType() *InterfaceType {
return (*InterfaceType)(unsafe.Pointer(t))
}
func (t *Type) ExportedMethods() []Method {
ut := t.Uncommon()
if ut == nil {
return nil
}
return ut.ExportedMethods()
}
func (t *Type) NumMethod() int {
if t.Kind() == Interface {
tt := (*InterfaceType)(unsafe.Pointer(t))
return tt.NumMethod()
}
return len(t.ExportedMethods())
}
// -----------------------------------------------------------------------------
// addChecked returns p+x.

View File

@@ -1525,7 +1525,6 @@ func (v Value) Type() Type {
}
func (v Value) typeSlow() Type {
/* TODO(xsw):
if v.flag == 0 {
panic(&ValueError{"reflect.Value.Type", Invalid})
}
@@ -1545,7 +1544,7 @@ func (v Value) typeSlow() Type {
panic("reflect: internal error: invalid method index")
}
m := &tt.Methods[i]
return toRType(typeOffFor(typ, m.Typ))
return toRType(&m.Typ_.Type)
}
// Method on concrete type.
ms := typ.ExportedMethods()
@@ -1553,9 +1552,7 @@ func (v Value) typeSlow() Type {
panic("reflect: internal error: invalid method index")
}
m := ms[i]
return toRType(typeOffFor(typ, m.Mtyp))
*/
panic("todo: reflect.Value.Type")
return toRType(&m.Mtyp_.Type)
}
// CanUint reports whether Uint can be used without panicking.