Skip to content

erroneous error: "to pass 'x' as ...interface { }, use 'x...'" #1297

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

Closed
rogpeppe opened this issue Nov 23, 2010 · 5 comments
Closed

erroneous error: "to pass 'x' as ...interface { }, use 'x...'" #1297

rogpeppe opened this issue Nov 23, 2010 · 5 comments

Comments

@rogpeppe
Copy link
Contributor

the following program fails to compile, with the error:
"to pass 'x' as ...interface { }, use 'x...'" although
it is valid according to the specification.

this applies also in the case where other
arguments follow x, which is less likely to be a mistake.

package main
import "fmt"
func main() { f(1,2,4) }
func f(x ...int) { fmt.Printf("[%v]\n", x) }

71a9509287b2+ tip
@griesemer
Copy link
Contributor

Comment 1:

Here is a self-contained package (no imports) showing the same problem:
package P
func f(x ...int) { g(x) }
func g(x ...interface{}){}
test.go:2: to pass 'x' as ...interface { }, use 'x...'
test.go:2: cannot use x (type []int) as type []interface { } in function argument
(both 6g and gccgo show an error). This may be a left-over error message to ease
transition to the  new rules.

Labels changed: added compilerbug.

Owner changed to [email protected].

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Dec 8, 2010

Comment 2:

You can work around this with interface{}(x).
I am reluctant to remove the error, even though
it is incorrect.

@rogpeppe
Copy link
Contributor Author

rogpeppe commented Dec 8, 2010

Comment 3:

i think it's ok if the error remains for the final argument case,
but where there are additional arguments like this:
var n int
func f(x ...int) { fmt.Printf("[%v] %d\n", x, n) }
i think it's less reasonable.
it was in that context i first encountered this error.

@gopherbot
Copy link
Contributor

Comment 4 by robert.hencke:

This seems to have been fixed in http://code.google.com/p/go/source/detail?r=e17a171b737b

@rsc
Copy link
Contributor

rsc commented Apr 25, 2011

Comment 5:

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants