Is there a place to track the proposal about "reflection on type arguments"?

92 views
Skip to first unread message

Jindong Zhang

unread,
Oct 29, 2021, 1:04:46 PM10/29/21
to golang-nuts
Hi there, 

I see there is a discussion about "reflection on type arguments" at the end of type parameters proposal (generics).
I am interested in this but don't find any futher discussion about this topic.
 So is there a place I can get the progress of this proposal?

Ian Lance Taylor

unread,
Oct 29, 2021, 1:12:28 PM10/29/21
to Jindong Zhang, golang-nuts
There hasn't been any discussion on that idea. There is no proposal
for it yet. I don't yet know whether any program actually needs the
information.

Ian

Jindong Zhang

unread,
Oct 29, 2021, 8:41:32 PM10/29/21
to golang-nuts
Thanks for your reply. 

Actually I am planning to build a mock framework which only receive a type parameter then mocks methods of such type.
So that I need to get the type information of the type parameter.

Currently I found I can do it by this way:
```
func (m *mock[T]) PrintType() {
   x := reflect.TypeOf((*T)(nil)).Elem()
   fmt.Printf("type is: %s\n", x)
}
```

But it's too tricky for me and not sure can it work in the future.
Reply all
Reply to author
Forward
0 new messages