Skip to content

Commit 88f9fc3

Browse files
committed
reflect: return correct name for unsafe.Pointer type
For some reason, the type kind name is "unsafe.Pointer" while the .Name() method just returns "Pointer". Not sure why this difference exists, but to be able to test .Name() in testdata/reflect.go it needs to match.
1 parent 84c3761 commit 88f9fc3

File tree

3 files changed

+97
-92
lines changed

3 files changed

+97
-92
lines changed

src/reflect/type.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,10 @@ func (t *rawType) Name() string {
10601060
panic("corrupt name data")
10611061
}
10621062

1063-
if t.Kind() <= UnsafePointer {
1063+
if kind := t.Kind(); kind < UnsafePointer {
10641064
return t.Kind().String()
1065+
} else if kind == UnsafePointer {
1066+
return "Pointer"
10651067
}
10661068

10671069
return ""

testdata/reflect.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ func showValue(rv reflect.Value, indent string) {
423423
if !rt.Comparable() {
424424
print(" comparable=false")
425425
}
426+
if name := rt.Name(); name != "" {
427+
print(" name=", name)
428+
}
426429
println()
427430
switch rt.Kind() {
428431
case reflect.Bool:

0 commit comments

Comments
 (0)