Skip to content

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

Description

@griesemer

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions