Skip to content

types2, go/types: the scope of a type parameter identifier in a method of a generic type is too large #51503

Description

@zigo101

What version of Go are you using (go version)?

$ go version
go version go1.18rc1 linux/amd64

What did you do?

type T[T any] struct {} // okay

func (T[T]) Bar() {} // error: T is not a generic type

What did you expect to see?

Compiles okay.

What did you see instead?

Fails to compile.

Honestly, the behavior conforms to the tip spec:

The scope of an identifier denoting a type parameter of a generic function or declared by a method receiver is the function body and all parameter lists of the function.

However, I think , for a method of a generic type, the scope should begin after the name of the generic type in the receiver, instead of beginning the start of receiver part.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

Type

No type

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions