Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions runtime/internal/lib/reflect/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ func pkgPathFor(t *abi.Type) string {

func (t *rtype) Name() string {
if !t.t.HasName() {
// For basic types (int, string, etc.), String() returns the type name directly.
// Basic types don't have TFlagNamed set, but they do have names.
if t.t.Kind() <= abi.UnsafePointer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation: Clarify basic type boundary

The comment mentions "basic types" but doesn't explain why <= abi.UnsafePointer is the boundary. Consider enhancing the comment to explain that this covers all predefined types (Invalid through UnsafePointer = kinds 0-25), while composite types (Array, Chan, Func, etc.) correctly return empty string when unnamed.

Suggested addition:

// For basic types (int, string, etc.), String() returns the type name directly.
// Basic types don't have TFlagNamed set, but they do have names.
// Check if Kind <= abi.UnsafePointer (25), which covers all basic predefined types
// from Invalid(0) through UnsafePointer(25). Types beyond this are composite types.

return t.String()
}
return ""
}
s := t.String()
Expand Down
Loading