go2go.playground - expected type, found 'type' (and 1 more errors)

Viewed 2260
2 Answers

That's old syntax since a few weeks ago. Try

type Pair[T any] struct { f1, f2 T }

Note that square brackets are now used instead of round brackets and the type keyword is no longer used. You also must use the any constraint, whereas previously you could leave the constraint out if there was no restriction on the type parameter.

BTW Conventionally Pair refers to a struct with 2 different types for the 2 fields like type Pair[T1, T2 any] struct { first T1; second T2 }

See go2go Playground for example code that builds.

As mentioned in the first paragraph of the 2019 design draft the new draft is https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md

Related