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

Comments

@gazerro
Copy link
Contributor

@gazerro 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 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

Loading

@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Jun 28, 2021

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.

Loading

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Jun 28, 2021

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.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 29, 2021

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

Loading

@gopherbot gopherbot closed this in fd4b587 Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants