New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't mix and explicit arg with varargs returned by a function call #41975
Comments
https://play.golang.org/p/tscYiZK493z |
A multi-value tuple can't mix with other values as one argument list in a function call (or the source value list in an assignment). |
This language behavior is designed and intended. We don't use the issue tracker to discuss language issues. Use a forum. See https://golang.org/wiki/Questions. Thanks. |
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. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?(whatever go playground is using)
go env
OutputWhat did you do?
Why do variadic args not work when mixing an explicit value with varargs returned by a function (args returned from a function)
WORKS:
https://play.golang.org/p/JNs31SQmAXc
DOESN'T WORK:
https://play.golang.org/p/UbGrrHUtoPe
https://play.golang.org/p/fVmZr1cGcJc
What did you expect to see?
Expected it to compile and run.
What did you see instead?
./prog.go:9:28: multiple-value test() in single-value context
The text was updated successfully, but these errors were encountered: