]> Cypherpunks.ru repositories - gostls13.git/commitdiff
spec: document illegal recursive type parameter lists
authorRobert Griesemer <gri@golang.org>
Wed, 14 Dec 2022 01:41:19 +0000 (17:41 -0800)
committerRobert Griesemer <gri@google.com>
Wed, 14 Dec 2022 19:13:24 +0000 (19:13 +0000)
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>
doc/go_spec.html

index 2cf53c8a979b95cf7d1d6a5ad380ca956a1768e9..237176f4a7675cbe38ac8cecc56bbdfdb17f027b 100644 (file)
@@ -2644,10 +2644,21 @@ of a <a href="#Method_declarations">method declaration</a> associated
 with a generic type.
 </p>
 
-<!--
-This section needs to explain if and what kind of cycles are permitted
-using type parameters in a type parameter list.
--->
+<p>
+Within a type parameter list of a generic type <code>T</code>, a type constraint
+may not (directly, or indirectly through the type parameter list of another
+generic type) refer to <code>T</code>.
+</p>
+
+<pre>
+type T1[P T1[P]] …                    // illegal: T1 refers to itself
+type T2[P interface{ T2[int] }] …     // illegal: T2 refers to itself
+type T3[P interface{ m(T3[int])}] …   // illegal: T3 refers to itself
+type T4[P T5[P]] …                    // illegal: T4 refers to T5 and
+type T5[P T4[P]] …                    //          T5 refers to T4
+
+type T6[P int] struct{ f *T6[P] }     // ok: reference to T6 is not in type parameter list
+</pre>
 
 <h4 id="Type_constraints">Type constraints</h4>