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

go/types: cannot assign "nil..." to ... parameters #18268

stjj89 opened this issue Dec 9, 2016 · 2 comments

go/types: cannot assign "nil..." to ... parameters #18268

stjj89 opened this issue Dec 9, 2016 · 2 comments


Copy link

stjj89 commented Dec 9, 2016

The following code is accepted by both gc and gccgo, but not go/types:

func foo(args ...string) {}

func bar() {

The error returned by go/types is

cannot use nil (untyped nil value) as parameter of type []string

It appears that go/types is wrong here. Per the spec
(, ):

If f is variadic with a final parameter p of type ...T, then within f the type of p is equivalent to type []T.
If the final argument is assignable to a slice type []T, it may be passed unchanged as the value for a ...T parameter if the argument is followed by .... In this case no new slice is created.

A value x is assignable to a variable of type T ("x is assignable to T") in any of these cases:

  • x is the predeclared identifier nil and T is a pointer, function, slice, map, channel, or interface type.
Copy link

I don't know why one would ever write that code, but you're right, the spec is pretty clear that it's a legal Go program.

/cc @griesemer

@mdempsky mdempsky added this to the Go1.9 milestone Dec 9, 2016
Copy link

CL mentions this issue.

@golang golang locked and limited conversation to collaborators Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

4 participants