This has to do with how type parameter names are scoped. There have to be *some* special handling of that, as they can be mutually referential. i.e. in `func F[T1 any, T2 C[T1]]()`, `T1` must be scoped such that it is visible for `C[T1]`, which is not a problem regular parameters face.
It is still possible to shadow type parameter names, though, by explicitly introducing a new scope: https://go.dev/play/p/ooMjxO2REdt?v=gotip In that way, the problem you observe is similar to shadowing a function-scoped type declaration, which also doesn't work: https://go.dev/play/p/QybMkt_yWOh Either way, this sort of shadowing seems unambiguously bad style. So while we *may* be able to allow it, as long as there is a clear way around (namely choosing a different variable name), it seems fine to start with the more restrictive route, until someone can come up with a good reason to need to do it. On Wed, Feb 16, 2022 at 11:45 AM Jochen Voss <jochen.v...@gmail.com> wrote: > Dear all, > > I stumbled across a difference between type names and type parameter names > (in the go1.18 beta): I can re-use a type name as a variable name, but the > same is not possible with type parameter names. Is this difference > intentional? > > For illustration, the following code is valid > https://go.dev/play/p/r2NAddZmoE3 : > > type other int > > func test(x other) other { > other := x + 1 > return other > } > > But this doesn't work https://go.dev/play/p/Dsh9IgvKDDY?v=gotip : > > type Numeric interface { > ~int | ~float64 > } > > func test[other Numeric](x other) other { > other := x + 1 > return other > } > > All the best, > Jochen > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/4d0066c3-315d-4746-a0cf-3749bfbcb45dn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/4d0066c3-315d-4746-a0cf-3749bfbcb45dn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfF9TCWtd5FmqZrWnx0grXmyiJYJFMNmtdNUrNP%3D9rFCZg%40mail.gmail.com.