Ran into this and I was wondering if it was a bug or not. Assuming "Foo" is
an interface with a function of "Bar", then the following function should
have a type reference of T and a pointer reference of P that implements the
Foo interface, and is bound to the Type of T
(https://gotipplay.golang.org/p/BKsA7-6MlHV).
*type Foo interface {*
* Bar() string }*
*func Update[T any, P interface { Foo *T}]() {*
Inside that function :
*var t T; t.Bar()* // gives
t.Bar undefined (type T has no field or method Bar)
*var t T; i:= &t; i.Bar()* // Gives
i.Bar undefined (type *T is pointer to type parameter, not type parameter)
But the following passes compile, and creates a new instance of type T,
with "i" being the pointer to it.
*var t T; var i P; i= &t; i.Bar()* // Pass
IMO all three ways should work, but curious as to why they don't
Thanks
Nz
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/205934b5-0b7e-4fe5-9912-402fdcb4db1fn%40googlegroups.com.