Skip to content

Commit

Permalink
reflect: return correct name for unsafe.Pointer type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aykevl committed Jul 31, 2024
1 parent 84c3761 commit 88f9fc3
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 92 deletions.
4 changes: 3 additions & 1 deletion src/reflect/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,10 @@ func (t *rawType) Name() string {
panic("corrupt name data")
}

if t.Kind() <= UnsafePointer {
if kind := t.Kind(); kind < UnsafePointer {
return t.Kind().String()
} else if kind == UnsafePointer {
return "Pointer"
}

return ""
Expand Down
3 changes: 3 additions & 0 deletions testdata/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ func showValue(rv reflect.Value, indent string) {
if !rt.Comparable() {
print(" comparable=false")
}
if name := rt.Name(); name != "" {
print(" name=", name)
}
println()
switch rt.Kind() {
case reflect.Bool:
Expand Down
Loading

0 comments on commit 88f9fc3

Please sign in to comment.