You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
typeT[Tany] 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.
This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group
No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group
rsc
changed the title
proposal: spec: adjust scope of type parameters declared by method receivers
spec: adjust scope of type parameters declared by method receivers
May 4, 2022
This proposal is about a small correction to the scope of function type parameters.
Per the current spec:
The proposal is to change this rule to:
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:
because the
T
inside the[T]
is visible inside the receiver parameter list and shadows the outerT
used in front of[T]
.If this proposal is accepted, it will be possible to write this code without errors.
See #51503.
The text was updated successfully, but these errors were encountered: