But package p3 does not know anything about the type p1.S. There may be no other call to p1.S.Identity elsewhere in the program. We need to instantiate p1.S.Identity[int] somewhere, but how?
The natural way would be to fetch instance sets (sets containing method implementations for any specified interface, here HasIdentity) as a matter of reflection.
However, solving instance resolution over reflection alludes to the following questions:
If all these questions can be answered by yes, then the case highlighted above is solvable.
Alternatively, modulating the "CheckIdentity" function by the compiler to:
serves providing an instance automatically by calling "CheckIdentity" function. This hidden parameter needs to be up-propagated to all callers passing p1.S down the caller-callee hierarchy.
Regarding the the section of No parameterized methods in go generics draft:package p1 // S is a type with a parameterized method Identity. type S struct{} // Identity is a simple identity method that works for any type. func (S) Identity[T any](v T) T { return v } package p2 // HasIdentity is an interface that matches any type with a // parameterized Identity method. type HasIdentity interface { Identity[T any](T) T } package p3 import "p2" // CheckIdentity checks the Identity method if it exists. // Note that although this function calls a parameterized method, // this function is not itself parameterized. 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" ) // CheckSIdentity passes an S value to CheckIdentity. func CheckSIdentity() { p3.CheckIden
This code seems corrupted (no newlines) and incomplete. It's hard to understand what your question is about without seeing the motivational code.
I hate mailing lists for exactly this reason.
Here is the code again:
```
p3.CheckIdentity(p1.S{})
}
```
Is there any option to highlight code here?
We need to instantiate p1.S.Identity[int] somewhere, but how?
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/420e8a74-d9f8-4df9-9d7b-efffb642fbe8n%40googlegroups.com.