From: Robert Griesemer Date: Wed, 14 Dec 2022 01:41:19 +0000 (-0800) Subject: spec: document illegal recursive type parameter lists X-Git-Tag: go1.20rc2~1^2~29 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5c682f94c6b465f75b3e638ecff77adaf87aabb2;p=gostls13.git 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 Reviewed-by: Ian Lance Taylor Reviewed-by: Robert Findley --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 2cf53c8a97..237176f4a7 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -2644,10 +2644,21 @@ of a method declaration associated with a generic type.

- +

+Within a type parameter list of a generic type T, a type constraint +may not (directly, or indirectly through the type parameter list of another +generic type) refer to T. +

+ +
+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
+

Type constraints