On Thu, Jan 27, 2022 at 1:38 PM Manlio Perillo <manlio.peri...@gmail.com> wrote: > > On Thu, Jan 27, 2022 at 10:00 PM Ian Lance Taylor <i...@golang.org> wrote: > > > > On Thu, Jan 27, 2022 at 3:13 AM Manlio Perillo <manlio.peri...@gmail.com> > > wrote: > > > > > > On Thursday, January 27, 2022 at 11:42:19 AM UTC+1 Manlio Perillo wrote: > > [...] > > > Here is an alternate implementation: > > > https://gotipplay.golang.org/p/mGm8DkqkuAX > > > > > > The code **seems** reasonable, but the compiler reports an error: > > > ./prog.go:24:12: *MyStruct does not implement structField > > > > I believe that that error message is correct. The constraint is for > > any type whose underlying type is "*struct{ x int }". The code is > > trying to instantiate with the type *MyStruct. The underlying type of > > *MyStruct is *MyStruct. It is not *struct{ x int }. So the type > > argument does not match the constraint. > > > > However (from the first example) MyStruct matches struct {x int }. > It seems a bit confusing that *MyStruct does not match *struct {x int }.
I do understand the confusion. Still, the rule for a constraint like "~*struct{ x int }" is that the underlying type of the type argument must be "*struct{ x int }". It's not reduce each type in the type argument to its underlying type and see if you wind up with "*struct { x int }"." We want to be precise here. Ian -- 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/CAOyqgcV83aSBEoVBTH%3DjS858OWEwLZCvmdp0qB8e9dUO%3D6qHfA%40mail.gmail.com.