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
{{ message }}
Repository navigation
spec: adjust scope of type parameters declared by method receivers #52038
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
changed the title [-]proposal: spec: adjust scope of type parameters declared by method receivers[/-][+]spec: adjust scope of type parameters declared by method receivers[/+]on May 4, 2022
Activity
[-]proposal: spec: [/-][+]proposal: spec: adjust scope of type parameters declared by method receivers[/+]rsc commentedon Mar 30, 2022
Given that
type T[T any] struct {}works today, it does seem reasonable to try to makefunc (T[T]) m() {}work too.rsc commentedon Mar 30, 2022
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
rsc commentedon Apr 13, 2022
Based on the discussion above, this proposal seems like a likely accept.
— rsc for the proposal review group
rsc commentedon May 4, 2022
No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group
[-]proposal: spec: adjust scope of type parameters declared by method receivers[/-][+]spec: adjust scope of type parameters declared by method receivers[/+]gopherbot commentedon May 11, 2022
Change https://go.dev/cl/405754 mentions this issue:
spec: adjust scope of function/method type paramatersspec: adjust scope of function/method type parameters