On 1/13/21 11:37 PM, Ian Lance Taylor wrote:
On Wed, Jan 13, 2021 at 12:39 PM Marcus Manning <icons...@gmail.com> wrote:
Does reflection support generic instantiation?
No. In the current proposal, generic functions and types are not
visible at run time. Only instantiated functions and types are
visible. So there is no way to even name a generic function/type that
should be instantiated.
Are generic types/functions are part of the runtime type information selectable
for runtime reflection?
No.
Are type to interface conformance relationships are part of the runtime type
information?
Yes, using reflect.Type.Implements.
Ian
Hmm..., then we should appreciate the alternative to generate a hidden
instance parameter for each instantiated type in the function body. The
hidden parameters might need to be up-propagated. Further, using
reflection, these hidden parameters have to be optionals or include nil
as we don't know if instances for a type parameter are available:
```
func CheckIdentity(v interface{})
{
if vi, ok := v.(p2.HasIdentity); ok {
if got := vi.Identity[int](0); got != 0 {
panic(got)
}
}
}
package p4 import ( "p1" "p3" )
p3.CheckIdentity(p1.s,
hiddenParameterIdentityInt?=p1.InterfaceInstanceOfSForInt)
p3.CheckIdentity(p1.someOtherStructNotHavingIdentityInstanceForInt,hiddenParameterIdentityInt?=nil)
```
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/28ec2495-18c3-8162-dc5e-9aae2fcce79b%40gmail.com.