package main
import "fmt"
func multipleRets() (int, int, int, int) {
return 11, 22, 33, 44
}
func main() {
// Q1
fmt.Println(multipleRets()) // This is fine.
fmt.Println(1, multipleRets()) // But this one errors.
// Q2
s1 := append([]int{}, []int{11, 22, 33, 44}...) // This is fine.
s2 := append([]int{}, multipleRets()) // But this one errors.
// Q3
lit1 := []int{11, 22, 33, 44} // This is fine.
lit2 := []int{multipleRets()} // But this one errors.
// Q4
fmt.Println(1, []int{11, 22, 33, 44}) // This is fine.
fmt.Println(1, []int{11, 22, 33, 44}...) // But this one errors.
}
There are 4 errors in a source code above, all of which complaining that multiple elements cannot be put in a function/literal.
But having the other examples in my mind, I can't really find a reason for those errors to be considered error.
Shouldn't they be fine? What does it mean when Go gives an error like that saying "multiple-value in single-value context"?
And the way those three pernicious dots work, how does that make sense? What exactly does ...
do?