| 1 |
// Copyright 2024 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package p |
| 6 |
|
| 7 |
type T[T any] struct{} |
| 8 |
|
| 9 |
// The inner T in T[T] must not conflict with the receiver base type T. |
| 10 |
func (T[T]) m1() {} |
| 11 |
|
| 12 |
// The receiver parameter r is declared after the receiver type parameter |
| 13 |
// r in T[r]. An error is expected for the receiver parameter. |
| 14 |
func (r /* ERROR "r redeclared" */ T[r]) m2() {} |
| 15 |
|
| 16 |
type C any |
| 17 |
|
| 18 |
// The scope of type parameter C starts after the type name (_) |
| 19 |
// because we want to be able to use type parameters in the type |
| 20 |
// parameter list. Hence, the 2nd C in the type parameter list below |
| 21 |
// refers to the first C. Since constraints cannot be type parameters |
| 22 |
// this is an error. |
| 23 |
type _[C C /* ERROR "cannot use a type parameter as constraint" */] struct{} |
| 24 |
|
| 25 |
// Same issue here. |
| 26 |
func _[C C /* ERROR "cannot use a type parameter as constraint" */]() {} |
| 27 |
|
| 28 |
// The scope of ordinary parameter C starts after the function signature. |
| 29 |
// Therefore, the 2nd C in the parameter list below refers to the type C. |
| 30 |
// This code is correct. |
| 31 |
func _(C C) {} // okay |