Description
This proposal is about a small correction to the scope of function type parameters.
Per the current spec:
The scope of an identifier denoting a type parameter of a function or declared by a method receiver is the function body and all parameter lists of the function.
The proposal is to change this rule to:
The scope of an identifier denoting a type parameter of a function or declared by a method receiver starts after the function name and ends at the end of the function body.
There is only a difference for methods of generic types: type parameters declared by method receivers won't be visible in the receiver parameter list anymore. For example, currently we get an error for:
type T[T any] struct {}
func (T[T]) m() {} // error: T is not a generic type
because the T
inside the [T]
is visible inside the receiver parameter list and shadows the outer T
used in front of [T]
.
If this proposal is accepted, it will be possible to write this code without errors.
See #51503.