diff options
Diffstat (limited to 'src/reflect')
| -rw-r--r-- | src/reflect/type.go | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/reflect/type.go b/src/reflect/type.go index 0e41a6db99..e5ee7f90d0 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -1303,6 +1303,11 @@ func TypeOf(i any) Type { return toType(abi.TypeOf(i)) } +// TypeFor returns the [Type] that represents the type argument T. +func TypeFor[T any]() Type { + return toType(abi.TypeFor[T]()) +} + // rtypeOf directly extracts the *rtype of the provided value. func rtypeOf(i any) *abi.Type { return abi.TypeOf(i) @@ -2850,12 +2855,3 @@ func addTypeBits(bv *bitVector, offset uintptr, t *abi.Type) { } } } - -// TypeFor returns the [Type] that represents the type argument T. -func TypeFor[T any]() Type { - var v T - if t := TypeOf(v); t != nil { - return t // optimize for T being a non-interface kind - } - return TypeOf((*T)(nil)).Elem() // only for an interface kind -} |
