]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: add test for receiver type parameters
authorRobert Griesemer <gri@golang.org>
Fri, 28 Jun 2024 18:12:48 +0000 (11:12 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 26 Jul 2024 20:15:36 +0000 (20:15 +0000)
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>

src/internal/types/testdata/fixedbugs/issue51503.go [new file with mode: 0644]

diff --git a/src/internal/types/testdata/fixedbugs/issue51503.go b/src/internal/types/testdata/fixedbugs/issue51503.go
new file mode 100644 (file)
index 0000000..90a4256
--- /dev/null
@@ -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