Skip to content
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

cmd/compile: internal error with variadic calls with a wrong number of arguments #46957

Closed
gazerro opened this issue Jun 28, 2021 · 4 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@gazerro
Copy link
Contributor

gazerro commented Jun 28, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/marco/Library/Caches/go-build"
GOENV="/Users/marco/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/marco/go/pkg/mod"
GOOS="darwin"
GOPATH="/Users/marco/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z9/xrln_qks56jbzxjbhs04fpm80000gn/T/go-build178768119=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Compile the following program

package main

func f(a int, b ...int) {}

func main() {
	f(nil...)
}

https://play.golang.org/p/q2VqTTvsay9

What did you expect to see?

./prog.go:6:3: not enough arguments in call to f
	have (...int)
	want (int, ...int)

What did you see instead?

./prog.go:6:3: internal compiler error: bad type for ... argument: nil

Please file a bug report including a short program that triggers the error.
https://golang.org/issue/new

The same error occurs using interface{}(nil) instead of the predeclared identifier nil:

package main

func f(a int, b ...int) {}

func main() {
	f(interface{}(nil)...)
}
./prog.go:6:3: internal compiler error: bad type for ... argument: interface {}
@gazerro gazerro changed the title cmd/compile: internal error with variadic calls with a wrong number of arguments and nil as last argument cmd/compile: internal error with variadic calls with a wrong number of arguments Jun 28, 2021
@gazerro
Copy link
Contributor Author

gazerro commented Jun 28, 2021

The internal error also occurs with any value not assignable to []T. For example:

package main

func f(a int, b ...int) {}

func main() {
	m := map[string]string{}
	f(m...)
}
./prog.go:7:3: internal compiler error: bad type for ... argument: map[string]string

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 28, 2021
@dmitshur
Copy link
Contributor

Thanks for reporting.

From brief testing, it looks like this issue is new to Go 1.16, and it still happens at tip. CC @mdempsky, @cherrymui.

@mdempsky
Copy link
Member

Thanks for the report. /cc @cuonglm

@dmitshur Is this backport eligible? The crash is unfortunate, but if it only affects invalid code, I'm inclined to think no. And the new typechecker in Go 1.18 should make this issue go away anyway.

@gopherbot
Copy link

Change https://golang.org/cl/331569 mentions this issue: cmd/compile: suppress details error for invalid variadic argument type

@golang golang locked and limited conversation to collaborators Jun 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants