Originally published on ImportStatic .
Since Go 1.27, a method on a concrete type may declare its own type parameters. On a current setup, "method must have no type parameters" therefore means one of two things: an older toolchain or an older go line in go.mod is still in charge, or the method is in an interface, where type parameters remain forbidden.
The exact wording of the message tells you which. We compiled this file, a small slice type with a generic Map method, under Go 1.25.13, 1.26.10 and 1.27.3 and collected every message:
type List [ T any ] [] T
// Map has its own type parameter R: a generic method. func ( l List [ T ]) Map [ R any ]( f func ( T ) R ) List [ R ] { out := make ( List [ R ], 0 , len ( l )) for _ , v := range l { out = append ( out , f ( v )) } return out }
func main () { nums := List [ int ]{ 1 , 2 , 3 } fmt . Printf ( "%q \n " , nums . Map ( strconv . Itoa )) }
Enter fullscreen mode
Exit fullscreen mode
With Go 1.27.3 and go 1.27 in go.mod, go vet is silent and go run .…