Skip to content

Commit 4684a26

Browse files
Robert Griesemergopherbot
authored andcommitted
spec: remove cycle restriction for type parameters
Fixes #75883. Change-Id: I708c0594ef3182d3aca37a6358aa0a0ef89809b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/711422 Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 0f9c8fb commit 4684a26

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

doc/go_spec.html

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Language version go1.26 (Nov 9, 2025)",
3+
"Subtitle": "Language version go1.26 (Nov 12, 2025)",
44
"Path": "/ref/spec"
55
}-->
66

@@ -2686,22 +2686,6 @@ <h3 id="Type_parameter_declarations">Type parameter declarations</h3>
26862686
with a generic type.
26872687
</p>
26882688

2689-
<p>
2690-
Within a type parameter list of a generic type <code>T</code>, a type constraint
2691-
may not (directly, or indirectly through the type parameter list of another
2692-
generic type) refer to <code>T</code>.
2693-
</p>
2694-
2695-
<pre>
2696-
type T1[P T1[P]] … // illegal: T1 refers to itself
2697-
type T2[P interface{ T2[int] }] … // illegal: T2 refers to itself
2698-
type T3[P interface{ m(T3[int])}] … // illegal: T3 refers to itself
2699-
type T4[P T5[P]] … // illegal: T4 refers to T5 and
2700-
type T5[P T4[P]] … // T5 refers to T4
2701-
2702-
type T6[P int] struct{ f *T6[P] } // ok: reference to T6 is not in type parameter list
2703-
</pre>
2704-
27052689
<h4 id="Type_constraints">Type constraints</h4>
27062690

27072691
<p>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2025 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+
// Test cases that were invalid because of cycles before the respective language change.
6+
// Some are still invalid, but not because of cycles.
7+
8+
package p
9+
10+
type T1[P T1[P]] struct{}
11+
type T2[P interface {
12+
T2[int /* ERROR "int does not satisfy interface{T2[int]}" */]
13+
}] struct{}
14+
type T3[P interface {
15+
m(T3[int /* ERROR "int does not satisfy interface{m(T3[int])}" */])
16+
}] struct{}
17+
type T4[P T5[P /* ERROR "P does not satisfy T4[P]" */]] struct{}
18+
type T5[P T4[P /* ERROR "P does not satisfy T5[P]" */]] struct{}
19+
20+
type T6[P int] struct{ f *T6[P] }

0 commit comments

Comments
 (0)