From 410617f73bb2bbf66fb2a54040e25ec814dad05e Mon Sep 17 00:00:00 2001 From: xushiwei Date: Tue, 16 Jul 2024 22:20:20 +0800 Subject: [PATCH] reflect.valueInterface --- internal/lib/reflect/value.go | 54 +++++++++++++++++------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/internal/lib/reflect/value.go b/internal/lib/reflect/value.go index 7e5f8c60..c2155266 100644 --- a/internal/lib/reflect/value.go +++ b/internal/lib/reflect/value.go @@ -747,36 +747,36 @@ func (v Value) Interface() (i any) { } func valueInterface(v Value, safe bool) any { - /* - if v.flag == 0 { - panic(&ValueError{"reflect.Value.Interface", Invalid}) - } - if safe && v.flag&flagRO != 0 { - // Do not allow access to unexported values via Interface, - // because they might be pointers that should not be - // writable or methods or function that should not be callable. - panic("reflect.Value.Interface: cannot return value obtained from unexported field or method") - } - if v.flag&flagMethod != 0 { - v = makeMethodValue("Interface", v) - } + if v.flag == 0 { + panic(&ValueError{"reflect.Value.Interface", Invalid}) + } + if safe && v.flag&flagRO != 0 { + // Do not allow access to unexported values via Interface, + // because they might be pointers that should not be + // writable or methods or function that should not be callable. + panic("reflect.Value.Interface: cannot return value obtained from unexported field or method") + } + if v.flag&flagMethod != 0 { + v = makeMethodValue("Interface", v) + } - if v.kind() == Interface { - // Special case: return the element inside the interface. - // Empty interface has one layout, all interfaces with - // methods have a second layout. - if v.NumMethod() == 0 { - return *(*any)(v.ptr) - } - return *(*interface { - M() - })(v.ptr) + if v.kind() == Interface { + /* TODO(xsw): + // Special case: return the element inside the interface. + // Empty interface has one layout, all interfaces with + // methods have a second layout. + if v.NumMethod() == 0 { + return *(*any)(v.ptr) } + return *(*interface { + M() + })(v.ptr) + */ + panic("todo: reflect.valueInterface") + } - // TODO: pass safe to packEface so we don't need to copy if safe==true? - return packEface(v) - */ - panic("todo: reflect.valueInterface") + // TODO: pass safe to packEface so we don't need to copy if safe==true? + return packEface(v) } // InterfaceData returns a pair of unspecified uintptr values.