Skip to content

Commit 5c682f9

Browse files
griesemerRobert Griesemer
authored and
Robert Griesemer
committed
spec: document illegal recursive type parameter lists
Fixes #40882. Change-Id: I90f99d75e6d66f857b6ab8789c6d436f85d20993 Reviewed-on: https://go-review.googlesource.com/c/go/+/457515 TryBot-Bypass: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
1 parent bd42aa8 commit 5c682f9

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

doc/go_spec.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,10 +2644,21 @@ <h3 id="Type_parameter_declarations">Type parameter declarations</h3>
26442644
with a generic type.
26452645
</p>
26462646

2647-
<!--
2648-
This section needs to explain if and what kind of cycles are permitted
2649-
using type parameters in a type parameter list.
2650-
-->
2647+
<p>
2648+
Within a type parameter list of a generic type <code>T</code>, a type constraint
2649+
may not (directly, or indirectly through the type parameter list of another
2650+
generic type) refer to <code>T</code>.
2651+
</p>
2652+
2653+
<pre>
2654+
type T1[P T1[P]] … // illegal: T1 refers to itself
2655+
type T2[P interface{ T2[int] }] … // illegal: T2 refers to itself
2656+
type T3[P interface{ m(T3[int])}] … // illegal: T3 refers to itself
2657+
type T4[P T5[P]] … // illegal: T4 refers to T5 and
2658+
type T5[P T4[P]] … // T5 refers to T4
2659+
2660+
type T6[P int] struct{ f *T6[P] } // ok: reference to T6 is not in type parameter list
2661+
</pre>
26512662

26522663
<h4 id="Type_constraints">Type constraints</h4>
26532664

0 commit comments

Comments
 (0)