Go 1.18, generics and fuzz testing

173 views
Skip to first unread message

Kamil Ziemian

unread,
Jan 26, 2022, 7:17:18 PM1/26/22
to golang-nuts
Hello,

I accidentally initialize go.mod files for both tutorial on generics (https://go.dev/doc/tutorial/generics) and for fuzzing (https://go.dev/doc/tutorial/fuzz) with command
> go mod init example/nameOfSubject
and as a result both contains in respective go.mod file line
> go 1.17

In the case of generic mere writing function definition
> func SumIntsOrFloats[K comparable, V int64 | float64](m map[K]V) V {
 >        var s V
        for _, v := range m {
                s += v
        }
        return s
}
without even calling it produce a compile error
> ./main.go:39:22: type parameters require go1.18 or later
To make it work I needed to change go.mod file to this with proper version 1.18.

But in the case of fuzzing I have done all the examples from tutorial without once encountering error of this type.

Can anyone check if it have similar issue? I don't know if it is minor problem or sign of some substantial flaw, but it is worth checking on few machines.

Best regards,
Kamil

Ian Lance Taylor

unread,
Jan 26, 2022, 7:22:36 PM1/26/22
to Kamil Ziemian, golang-nuts
Fuzzing is implemented in the tools, not the language itself, so if
you are using the 1.18 tools it works regardless of the requested
language version.

Ian

Kamil Ziemian

unread,
Jan 27, 2022, 4:38:06 AM1/27/22
to golang-nuts
Thank you for information. There is so many things about Go and its tool chain that I need to learn and think about.

Best regards,
Kamil
Reply all
Reply to author
Forward
0 new messages