Closed
Description
What version of Go are you using (go version
)?
https://go.dev/play/p/Ztyu2FJaajl go1.20.1
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
Go Playground server
What did you do?
package main
type A[T any, U ~T] struct{}
type B[T any, U ~T | ~*T] struct{}
type C[T any] interface{ ~T | ~*T }
func main() {}
What did you expect to see?
no error
What did you see instead?
./prog.go:3:18: type in term ~T cannot be a type parameter
./prog.go:4:18: type in term ~T cannot be a type parameter
./prog.go:5:27: type in term ~T cannot be a type parameter
Go build failed.
Too bad Google isn't using numbered sections in the Go spec, that would make it easier to cite precise specification items.
So constraints are interfaces and implicitly converted to them using the syntax of the first four examples. The spec states that "An interface type T
may not embed a type element that is, contains, or embeds T
, directly or indirectly." However, we're specifying a type with T as an underlying type. If I read the specification correctly then this should be legal.
It's probably a separate issue with the specification that a constraint of type A[T any, U T | *T] struct{}
is not legal.