use 

   type Test[T, V interface{A; I}] struct{}

instead now. 

There are still several restrictions in custom generics: 
https://go101.org/generics/888-the-status-quo-of-go-custom-generics.html

On Monday, February 26, 2024 at 10:44:46 PM UTC+8 Albert Widiatmoko wrote:

> Hi Go community,
>
> I was playing with Go generics and writing some codes, but I faced some 
> problems. I want to ask questions and help from the community if possible. 
> Below, I am trying to build a generic struct via a method through another 
> generic struct.
>
> Here's the link to Go Playground: https://go.dev/play/p/Q0zOJUePkmR
>
> ---
>
> package main
>
> var _ I = (*A)(nil)
>
> type I interface {
> String() string
> }
>
> type A struct {
> str string
> }
>
> func (a A) String() string {
> return a.str
> }
>
> type AE[T, V I] struct {
> T1 T
> T2 V
> }
>
> // func (AE[T, V]) String() string {
> // return "test"
> // }
>
> type Test[T, V A] struct{}
>
> func (t Test[T, V]) S() AE[T, V] {
> return AE[T, V]{}
> }
>
> func main() {}
>
> ---
>
> I expected the program to run, but then I got an error:
>
> T does not satisfy I (missing method String)
>
> I a bit confused because A implements I interface. I think this must be 
> because I missed something with the Go generics.
>
> Thank you.
>
>

-- 
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/e3288ddb-e86f-4886-b5da-c66a4617ecebn%40googlegroups.com.

Reply via email to