1
0
mirror of https://github.com/golang/go synced 2024-11-21 17:24:42 -07:00

go/types, types2: add test for receiver type parameters

Issue #51503 was fixed with the rewrite in CL 594740.
Add a respective test case.

Fixes #51503.
For #51343.

Change-Id: Iff9e7e3274c5ad40789e107b6f62d17e335e2428
Reviewed-on: https://go-review.googlesource.com/c/go/+/595697
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2024-06-28 11:12:48 -07:00 committed by Gopher Robot
parent ea82219d1c
commit 9e40780a46

View File

@ -0,0 +1,31 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package p
type T[T any] struct{}
// The inner T in T[T] must not conflict with the receiver base type T.
func (T[T]) m1() {}
// The receiver parameter r is declared after the receiver type parameter
// r in T[r]. An error is expected for the receiver parameter.
func (r /* ERROR "r redeclared" */ T[r]) m2() {}
type C any
// The scope of type parameter C starts after the type name (_)
// because we want to be able to use type parameters in the type
// parameter list. Hence, the 2nd C in the type parameter list below
// refers to the first C. Since constraints cannot be type parameters
// this is an error.
type _[C C /* ERROR "cannot use a type parameter as constraint" */] struct{}
// Same issue here.
func _[C C /* ERROR "cannot use a type parameter as constraint" */]() {}
// The scope of ordinary parameter C starts after the function signature.
// Therefore, the 2nd C in the parameter list below refers to the type C.
// This code is correct.
func _(C C) {} // okay