internal/lib/reflect: Value.IsZero

This commit is contained in:
visualfc
2024-11-14 10:35:01 +08:00
parent 792716eefc
commit 5fb8503fd2

View File

@@ -22,6 +22,7 @@ package reflect
import ( import (
"errors" "errors"
"math"
"unsafe" "unsafe"
"github.com/goplus/llgo/c/bitcast" "github.com/goplus/llgo/c/bitcast"
@@ -843,7 +844,6 @@ func (v Value) IsValid() bool {
// IsZero reports whether v is the zero value for its type. // IsZero reports whether v is the zero value for its type.
// It panics if the argument is invalid. // It panics if the argument is invalid.
func (v Value) IsZero() bool { func (v Value) IsZero() bool {
/*
switch v.kind() { switch v.kind() {
case Bool: case Bool:
return !v.Bool() return !v.Bool()
@@ -901,8 +901,6 @@ func (v Value) IsZero() bool {
// as a default value doesn't makes sense here. // as a default value doesn't makes sense here.
panic(&ValueError{"reflect.Value.IsZero", v.Kind()}) panic(&ValueError{"reflect.Value.IsZero", v.Kind()})
} }
*/
panic("todo: reflect.Value.IsZero")
} }
// SetZero sets v to be the zero value of v's type. // SetZero sets v to be the zero value of v's type.
@@ -1793,6 +1791,9 @@ func Zero(typ Type) Value {
// must match declarations in runtime/map.go. // must match declarations in runtime/map.go.
const maxZero = runtime.MaxZero const maxZero = runtime.MaxZero
//go:linkname zeroVal runtime.ZeroVal
var zeroVal [maxZero]byte
// New returns a Value representing a pointer to a new zero value // New returns a Value representing a pointer to a new zero value
// for the specified type. That is, the returned Value's Type is PointerTo(typ). // for the specified type. That is, the returned Value's Type is PointerTo(typ).
func New(typ Type) Value { func New(typ Type) Value {