Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Can't mix and explicit arg with varargs returned by a function call #41975
What version of Go are you using (
I believe it is converted to a slice implicitly. Hence why the first example works as shown in the code fragment on Playground.
The types of all elements of a slice are the same one,. For a multi-value expression, it is not true.
Yes, for the workable case (https://play.golang.org/p/JNs31SQmAXc), a multi-value expression (tuple) is expanded to multiple single values and these single values are then converted (appended) into a slice. You can also think the slice is converted from the tuple directly, but this is not the key of this issue. Actually, compilers may also convert (a multi-value expression + other value expressions) shown in the unworkable cases to a slice, if Go specification allows such conversions.
There are surely some reasons why the spec prohibits them. You can look for the reasons in some Go forms/groups. The current rules might be some over-stricter for some cases. If you do think the rules should be relaxed, you could make a formal proposal instead of reporting it as a bug.