Using golang's multiple returns functionality, is there any limit of returns allowed? Or could a user hypothetically have millions of returns on a function, assuming memory size isn't an issue.
In theory, there is no limit.
https://golang.org/ref/spec#ExpressionList
In practice, of course, it will fail at some point.
1000 output parameters: https://play.golang.org/p/pOf4YCahtER
On my computer, I was able to push it to 8190 output parameters with Go 1.11.5. The output list was a series of i
s (type i int
) and the return statement contained a series of 0
s.
Changing to name of the type to ii
lowered the maximum I was able to achieve. This suggests that the limit comes from the length of the string that represents the output parameters, not the number of elements in the list.
This seems to be the returned error when the list is too long: https://github.com/golang/go/blob/ed15e82413c7b16e21a493f5a647f68b46e965ee/src/cmd/compile/internal/gc/reflect.go#L544