What version of Go are you using (go version)?
$ go version
go version go1.18rc1 linux/amd64
What did you do?
type T[T any] struct {} // okay
func (T[T]) Bar() {} // error: T is not a generic type
What did you expect to see?
Compiles okay.
What did you see instead?
Fails to compile.
Honestly, the behavior conforms to the tip spec:
The scope of an identifier denoting a type parameter of a generic function or declared by a method receiver is the function body and all parameter lists of the function.
However, I think , for a method of a generic type, the scope should begin after the name of the generic type in the receiver, instead of beginning the start of receiver part.
What version of Go are you using (
go version)?What did you do?
What did you expect to see?
Compiles okay.
What did you see instead?
Fails to compile.
Honestly, the behavior conforms to the tip spec:
However, I think , for a method of a generic type, the scope should begin after the name of the generic type in the receiver, instead of beginning the start of receiver part.