mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-04 10:57:50 +08:00
29 lines
697 B
Go
29 lines
697 B
Go
package vals
|
|
|
|
import "reflect"
|
|
|
|
var (
|
|
dummy any
|
|
nilValue = reflect.ValueOf(&dummy).Elem()
|
|
emptyInterfaceType = reflect.TypeOf(&dummy).Elem()
|
|
)
|
|
|
|
// ValueOf is like reflect.ValueOf, except that when given an argument of nil,
|
|
// it does not return a zero Value, but the Value for the zero value of the
|
|
// empty interface.
|
|
func ValueOf(i any) reflect.Value {
|
|
if i == nil {
|
|
return nilValue
|
|
}
|
|
return reflect.ValueOf(i)
|
|
}
|
|
|
|
// TypeOf is like reflect.TypeOf, except that when given an argument of nil, it
|
|
// does not return nil, but the Type for the empty interface.
|
|
func TypeOf(i any) reflect.Type {
|
|
if i == nil {
|
|
return emptyInterfaceType
|
|
}
|
|
return reflect.TypeOf(i)
|
|
}
|