Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: adjust scope of type parameters declared by method receivers #52038

Closed
griesemer opened this issue Mar 30, 2022 · 5 comments
Closed

spec: adjust scope of type parameters declared by method receivers #52038

griesemer opened this issue Mar 30, 2022 · 5 comments

Comments

@griesemer
Copy link
Contributor

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.

@griesemer griesemer added this to the Go1.19 milestone Mar 30, 2022
@griesemer griesemer changed the title proposal: spec: proposal: spec: adjust scope of type parameters declared by method receivers Mar 30, 2022
@rsc
Copy link
Contributor

rsc commented Mar 30, 2022

Given that type T[T any] struct {} works today, it does seem reasonable to try to make func (T[T]) m() {} work too.

@rsc
Copy link
Contributor

rsc commented 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 rsc added this to Active in Proposals (old) Mar 30, 2022
@griesemer griesemer self-assigned this Mar 30, 2022
@rsc
Copy link
Contributor

rsc commented Apr 13, 2022

Based on the discussion above, this proposal seems like a likely accept.
— rsc for the proposal review group

@rsc rsc moved this from Active to Likely Accept in Proposals (old) Apr 13, 2022
@rsc rsc moved this from Likely Accept to Accepted in Proposals (old) May 4, 2022
@rsc
Copy link
Contributor

rsc commented 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

@rsc 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
@gopherbot
Copy link

Change https://go.dev/cl/405754 mentions this issue: spec: adjust scope of function/method type paramaters

@golang golang locked and limited conversation to collaborators Jun 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

3 participants