1
0

safe type checks

This commit is contained in:
Arpad Ryszka 2025-08-31 17:16:19 +02:00
parent 9e0dcd6677
commit 9aa6df75cb

14
type.go
View File

@ -46,7 +46,12 @@ func scalarType(t reflect.Type) Scalar {
} }
func scalarTypeReflect(v any) Scalar { func scalarTypeReflect(v any) Scalar {
return scalarType(reflect.TypeOf(v)) t := reflect.TypeOf(v)
if t == nil {
return Any
}
return scalarType(t)
} }
func scalarSize(t reflect.Type) int { func scalarSize(t reflect.Type) int {
@ -67,7 +72,12 @@ func valueSize(v reflect.Value) int {
} }
func valueSizeReflect(v any) int { func valueSizeReflect(v any) int {
return valueSize(reflect.ValueOf(v)) r := reflect.ValueOf(v)
if hasCircularReference(r) {
return 0
}
return valueSize(r)
} }
func setVisited[T comparable](visited map[T]bool, k T) map[T]bool { func setVisited[T comparable](visited map[T]bool, k T) map[T]bool {