diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 2849d4ee40f..15173c54dcc 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -717,6 +717,10 @@ func writeType(t *types.Type) *obj.LSym { } s.SetSiggen(true) + if !tbase.HasShape() { + TypeLinksym(t) // ensure lsym.Extra is set + } + if !NeedEmit(tbase) { if i := typecheck.BaseTypeIndex(t); i >= 0 { lsym.Pkg = tbase.Sym().Pkg.Prefix diff --git a/src/reflect/type.go b/src/reflect/type.go index cec8662c01a..fc6edb1e106 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -1314,7 +1314,8 @@ func TypeOf(i any) Type { // TypeFor returns the [Type] that represents the type argument T. func TypeFor[T any]() Type { - return toType(abi.TypeFor[T]()) + // toRType is safe to use here; type is never nil as T is statically known. + return toRType(abi.TypeFor[T]()) } // rtypeOf directly extracts the *rtype of the provided value. diff --git a/test/codegen/reflect_type.go b/test/codegen/reflect_type.go new file mode 100644 index 00000000000..b92a9567f14 --- /dev/null +++ b/test/codegen/reflect_type.go @@ -0,0 +1,21 @@ +// asmcheck + +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package codegen + +import "reflect" + +func intPtrTypeSize() uintptr { + // amd64:"MOVL\t[$]8,",-"CALL" + // arm64:"MOVD\t[$]8,",-"CALL" + return reflect.TypeFor[*int]().Size() +} + +func intPtrTypeKind() reflect.Kind { + // amd64:"MOVL\t[$]22,",-"CALL" + // arm64:"MOVD\t[$]22,",-"CALL" + return reflect.TypeFor[*int]().Kind() +}