diff options
| author | Robert Griesemer <gri@golang.org> | 2021-11-08 16:09:11 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2021-11-10 00:56:09 +0000 |
| commit | cc14fcac2bc1d452841336b9aeee3b1d47880f37 (patch) | |
| tree | eb2a41ef7dc27c1adbc981e24fd914fa987b42e1 /test/typeparam | |
| parent | 318c024b498621932ace08736c38a51fe5519a63 (diff) | |
| download | go-cc14fcac2bc1d452841336b9aeee3b1d47880f37.tar.xz | |
cmd/compile/internal/types2: disallow type cycles through type parameter lists
If we reach a generic type that is part of a cycle
and we are in a type parameter list, we have a cycle
through a type parameter list, which is invalid.
Fixes #49439.
Change-Id: Ia6cf97e1748ca0c0e61c02841202050091365b0b
Reviewed-on: https://go-review.googlesource.com/c/go/+/361922
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'test/typeparam')
| -rw-r--r-- | test/typeparam/issue46461.go | 4 | ||||
| -rw-r--r-- | test/typeparam/issue46461b.dir/a.go | 2 | ||||
| -rw-r--r-- | test/typeparam/issue46461b.dir/b.go | 4 | ||||
| -rw-r--r-- | test/typeparam/issue48280.dir/a.go | 2 | ||||
| -rw-r--r-- | test/typeparam/issue48306.dir/a.go | 2 |
5 files changed, 8 insertions, 6 deletions
diff --git a/test/typeparam/issue46461.go b/test/typeparam/issue46461.go index 2c54a6ba28..8fdec1c073 100644 --- a/test/typeparam/issue46461.go +++ b/test/typeparam/issue46461.go @@ -1,4 +1,4 @@ -// compile -G=3 +// errorcheck -G=3 // Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -6,7 +6,7 @@ package p -type T[U interface{ M() T[U] }] int +type T[U interface{ M() T[U] }] int // ERROR "invalid recursive type T" type X int diff --git a/test/typeparam/issue46461b.dir/a.go b/test/typeparam/issue46461b.dir/a.go index 0d53b3e204..fcb414266d 100644 --- a/test/typeparam/issue46461b.dir/a.go +++ b/test/typeparam/issue46461b.dir/a.go @@ -4,4 +4,4 @@ package a -type T[U interface{ M() T[U] }] int +type T[U interface{ M() int }] int diff --git a/test/typeparam/issue46461b.dir/b.go b/test/typeparam/issue46461b.dir/b.go index 3393a375c2..a4583257ff 100644 --- a/test/typeparam/issue46461b.dir/b.go +++ b/test/typeparam/issue46461b.dir/b.go @@ -8,4 +8,6 @@ import "./a" type X int -func (X) M() a.T[X] { return 0 } +func (X) M() int { return 0 } + +type _ a.T[X] diff --git a/test/typeparam/issue48280.dir/a.go b/test/typeparam/issue48280.dir/a.go index 17859e6aa9..f66fd30e34 100644 --- a/test/typeparam/issue48280.dir/a.go +++ b/test/typeparam/issue48280.dir/a.go @@ -4,7 +4,7 @@ package a -type I[T I[T]] interface { +type I[T any] interface { F() T } diff --git a/test/typeparam/issue48306.dir/a.go b/test/typeparam/issue48306.dir/a.go index 739750b20b..fdfd86cb6d 100644 --- a/test/typeparam/issue48306.dir/a.go +++ b/test/typeparam/issue48306.dir/a.go @@ -4,6 +4,6 @@ package a -type I[T I[T]] interface { +type I[T any] interface { F() T } |
