We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
go version
$ go version 1.17.8
Yes
go env
$ go env GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/marco/Library/Caches/go-build" GOENV="/Users/marco/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/marco/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/marco/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/opt/homebrew/Cellar/go/1.17.8/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/opt/homebrew/Cellar/go/1.17.8/libexec/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.17.8" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/sdev/golang/abds-go/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/03/csncw3x15h54rjwv14wsf6x40000gn/T/go-build2466302340=/tmp/go-build -gno-record-gcc-switches -fno-common"
GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/marco/Library/Caches/go-build" GOENV="/Users/marco/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/marco/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/marco/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/opt/homebrew/Cellar/go/1.17.8/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/opt/homebrew/Cellar/go/1.17.8/libexec/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.17.8" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/sdev/golang/abds-go/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/03/csncw3x15h54rjwv14wsf6x40000gn/T/go-build2466302340=/tmp/go-build -gno-record-gcc-switches -fno-common"
Passing variadic parameters further down the function call stack mangles the parameter.
Run this in the Go Playground:
package main
import ( "fmt" )
func one(parms ...interface{}) {
fmt.Println("One#######") for idx,parm := range parms { fmt.Println(idx,parm) } two(parms)
}
func two(parms ...interface{}) {
fmt.Println("Two#######") for idx,parm := range parms { fmt.Println(idx,parm) }
func main() { one(11,12,13) }
One####### 0 11 1 12 2 13 Two####### 0 11 1 12 2 13
One####### 0 11 1 12 2 13 Two####### 0 [11 12 13]
The text was updated successfully, but these errors were encountered:
The code is working correctly. The example has a bug given your intent: two(parms) needs to be two(parms...).
two(parms)
two(parms...)
Otherwise you are passing the slice of arguments as the first parameter to two. Hence you see the slice output [11 12 13].
two
[11 12 13]
Sorry, something went wrong.
When calling the two( ) function, you must add the spread operator
Then it works ok.
No branches or pull requests
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
)?go env
OutputWhat did you do?
Passing variadic parameters further down the function call stack mangles the parameter.
Run this in the Go Playground:
package main
import (
"fmt"
)
func one(parms ...interface{}) {
}
func two(parms ...interface{}) {
}
func main() {
one(11,12,13)
}
What did you expect to see?
One#######
0 11
1 12
2 13
Two#######
0 11
1 12
2 13
What did you see instead?
One#######
0 11
1 12
2 13
Two#######
0 [11 12 13]
The text was updated successfully, but these errors were encountered: