Description
The type parameters proposal (https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#reflection) states:
We do not propose to change the reflect package in any way. When a type or function is instantiated, all of the type parameters will become ordinary non-generic types. The String method of a reflect.Type value of an instantiated type will return the name with the type arguments in square brackets. For example, List[int].
It's ambiguous what "name" should be used. Also, whether only reflect.Type.String should have been affected, or reflect.Type.Name too.
cmd/compile generates two names for each type: a "link name" that corresponds to type identity (so the linker can deduplicate it against other identical types), and a "reflect name" that's simplified somewhat for user presentation via reflect APIs.
However, for instantiated types' reflect names, it currently uses the link names of the type arguments. For example: https://go.dev/play/p/JAP28idHc9z
Can/should we change this behavior?
Some noteworthy distinctions:
- Reflect names use package name, whereas link names use package path. (reflect.Type.String says either is allowed though.)
- Link names add "·N" suffixes to locally defined types to disambiguate them, whereas reflect names omit this.
- Link names include package-path-qualifiers for non-exported struct fields and interface methods.
- Link names include a
=
byte to identify embedded fields.
/cc @rsc @ianlancetaylor @griesemer @golang/compiler
Metadata
Metadata
Assignees
Labels
Type
Projects
Status