From 9e40780a4633fd104777243fe2b5d07bc482d5a6 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 28 Jun 2024 11:12:48 -0700 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Findley Auto-Submit: Robert Griesemer --- .../types/testdata/fixedbugs/issue51503.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/internal/types/testdata/fixedbugs/issue51503.go diff --git a/src/internal/types/testdata/fixedbugs/issue51503.go b/src/internal/types/testdata/fixedbugs/issue51503.go new file mode 100644 index 0000000000..90a4256229 --- /dev/null +++ b/src/internal/types/testdata/fixedbugs/issue51503.go @@ -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 -- 2.48.1